开发者

Slow down a calculation in iOS.

Not sure if this is possible, or recommended, however, I have an iPhone application which performs calculations based on my users Age, Height and Weight. When I tap my calculate button, the resultant output is immediate in that the calc is performed and my UILabel is populated instantaneously.

Is it possible to slow this down and give a 'calculating' o开发者_如何学Cn view alert then populate the label?


You could create a simple NSTimer that gets fired and then use a UIActivityIndicatorView (for example) to show the "loading/calculating" progress inside a view (or even put it inside a UIAlertView) in your app, and then once the timer is complete, uncover the calculated label.

Hope this helps :)

--

Edit; added sample code

spinnerAlertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"My App Name", @"") message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil] autorelease]; // member
spinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)]; // member
spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[spinnerAlertView addSubview: spinner];
[spinner startAnimating];
[spinnerAlertView show];

Then when the calculation is complete, remember to do this:

[spinnerAlertView dismissWithClickedButtonIndex:0 animated:TRUE];

You could tell it to stop animating and hide it from the main view, but this way we just remove it as if though the user dismissed it... much easier.


When your button is clicked, display your loading alert and do this:

[self performSelector:@selector(calculate) withObject:nil afterDelay:1];

- (void)calculate {
//do your calulation and update the result label
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜