开发者

DSBezelActivityView not working

Here is a piece of code that I'm having problems with:

-(IBAction) nextRegister {
    [DSBezelActivityView newActivityViewForView:self.view.superview];
    previousPosition = (NSInteger *) currentPosition;
    currentPosition = (NSInteger *) ((int)currentPosition + (int) 1 );    
    [currentRegistry updateOnServer];
    [self loadNewRegisterInfos];
    [DSBezelActivityView removeViewAnimated:YES];开发者_运维技巧
}

Line by line, here is what this snippet does (or should do):

Show a DSBezelActivityView (from this: http://www.dejal.com/developer/dsactivityview)

Previous position receives actual position (since this will move to the next)

Next is current + 1;

Updates record in server (this takes ~1s)

Loads new record and renders on screen (this takes 1~3s, tops)

This line removes the DSBezelActivityView.

So, when I tap the button to load next record, it is supposed to show the ActivityView, load the data, then update the screen and release the ActivityView. But what happens is: It freezes the app for 3s, shows and dismisses the activity view in less than a second and then finishes the routine. What is wrong?


[Edited] Resolved! Its a thread issue. Split among 4 methods:

-(IBAction) nextRegister {
    [NSThread detachNewThreadSelector:@selector(openActivityView) toTarget:self     withObject:nil];
    [self viewNextRegister];
    [self removeView];
}

-(void)viewNextRegister{
    previousPosition = (NSInteger *) currentPosition;
    currentPosition = (NSInteger *) ((int)currentPosition + (int) 1 );
    [currentRegister setScoreOnServer];
    //    [NSThread detachNewThreadSelector:@selector(loadRegisterInfo) toTarget:self withObject:nil];
    [self loadRegisterInfo];
}

-(void)openActivityView{
    [DSBezelActivityView newActivityViewForView:self.view.superview];
}

-(void)removeView {
    [DSBezelActivityView removeViewAnimated:YES];    
}


Rather than a separate thread which can cause issues if you aren't careful you can also do:

-(void) doNextRegister {
    previousPosition = (NSInteger *) currentPosition;
    currentPosition = (NSInteger *) ((int)currentPosition + (int) 1 );    
    [currentRegistry updateOnServer];
    [self loadNewRegisterInfos];
    [DSBezelActivityView removeViewAnimated:YES];
}

-(IBAction) nextRegister {
    [DSBezelActivityView newActivityViewForView:self.view.superview];
    [self performSelector:@selector(doNextRegister) withObject:nil afterDelay:0.0];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜