iphone - Issue: iOS UITableView scrolling stops other task -


i developing application running based on async socket communication on tcpip. aim of app fetch data cyclicly(2 second) server , list down datas on tableview.

up point have done coding , everything. app working fine. however, when start scrolling in uitableview, cyclic fetching stops until tableviews declares end of scrolling.

instead of adding codes adding sample code having same behavior. in sample project have created timer. there label show counter , button start/stop timer on screen. in screen have added uitextview has quite long text have scrolling enabled.

here code

#import <uikit/uikit.h> int i;  @interface viewcontroller : uiviewcontroller{    }  @property (strong, nonatomic)  nstimer *timer;  @property (strong, nonatomic) iboutlet uilabel *label; @property (strong, nonatomic) iboutlet uibutton *txtbtn; - (ibaction)btnstartstop:(id)sender;  @end   #import "viewcontroller.h"  @interface viewcontroller ()  @end  @implementation viewcontroller  @synthesize label,txtbtn, timer;  - (void)viewdidload {     [super viewdidload];     // additional setup after loading view, typically nib.     = 0;     //timer = [[nstimer alloc] init]; }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  - (ibaction)btnstartstop:(id)sender {     if ([txtbtn.titlelabel.text isequaltostring:@"start"]) {         [txtbtn settitle:@"stop" forstate:uicontrolstatenormal];          timer = [nstimer scheduledtimerwithtimeinterval:1.0 target:self selector:@selector(timer_running) userinfo:nil repeats:yes];             nslog(@"timer started");     }     else{         [txtbtn settitle:@"start" forstate:uicontrolstatenormal];         [timer invalidate];         nslog(@"timer stopped");     }   }  -(void)timer_running{     nslog(@"timer running");     label.text = [nsstring stringwithformat:@"%i", i];     i++; }   @end 

for above code; when click on start button, counter starts , on label can see increment each 1s. once touch , scroll up/down on uitextview count not increase, wait until scrolling end , counter contunious increment.

can tell me possible reason , how avoid issue.

thanks.

firstly, need have timer initiated background thread. replace code have initiate timer this:

timer = [nstimer timerwithtimeinterval:0.1                                          target:self                               selector:@selector(timer_running:)                                        userinfo:nil repeats:yes]; [[nsrunloop mainrunloop] addtimer:timer formode:nsrunloopcommonmodes]; 

secondly, since timer fired in background thread, need access uikit main thread:

-(void) timer_running:(nstimer *)timer {     dispatch_async(dispatch_get_main_queue(), ^{         nslog(@"timer running");         label.text = [nsstring stringwithformat:@"%i", i];     });     i++; } 

note i++ needs not scheduled on main queue. code above has been tested code , shown work.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -