I have the code for the iOS application that I am developing, and for some reason, what seems like a quick and easy task makes my iPhone 4S execute a full second or more each time.
The context is ... I have an ActionSheet popup with 2 buttons, and if the user clicks one of the buttons, the application seems to stop for about a second. Here is the code:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 0) { UIAlertView* newTimerAlertView = [[[UIAlertView alloc] initWithTitle:@"Create New Timer" message:@"Enter a name for your new indicator" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Create", nil] autorelease]; newTimerAlertView.tag = kNewTimer; newTimerAlertView.alertViewStyle = UIAlertViewStylePlainTextInput; [newTimerAlertView show]; } else if (buttonIndex == 1) { NSLog(@"ActionSheet button 2 tapped"); UIAlertView* newTallyAlertView = [[[UIAlertView alloc] initWithTitle:@"Create New Tally" message:@"Enter a name for your new indicator" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Create", nil] autorelease]; newTallyAlertView.tag = kNewTally; newTallyAlertView.alertViewStyle = UIAlertViewStylePlainTextInput; [newTallyAlertView show]; NSLog(@"end"); } }
Focusing on the second button for simplicity (although the first button behaves the same), the log looks like this:
2012-01-25 20:35:46.330 ...[177:707] ActionSheet button 2 tapped 2012-01-25 20:35:47.194 ...[177:707] end 2012-01-25 20:35:56.154 ...[177:707] ActionSheet button 2 tapped 2012-01-25 20:35:56.180 ...[177:707] end
Please note that the first time I tried it, it takes a second before the code fragment completes execution, but the second time (and all subsequent times) the code takes only about 30 or less milliseconds.
Is there something wrong with the code? or do I just need to compensate for the delay in viewing progress?
Thanks!
EDIT: This only happens on devices when starting the application from Xcode ... maybe this is due to the debugger?
source share