我的UIAlertView消息有问题,我需要用循环
更改警告消息首先,
我在实现中声明了这个
NSString *alertMessage;
UIAlertView *theAlert;
和
- (IBAction)doSearching:(id)sender
{
theAlart = [[UIAlertView alloc] initWithTitle:nil message:@"Searching..."
delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
[theAlart show];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self
selector:@selector(searchAfterAlertShow) userInfo:nil repeats:NO];
}
- (void)searchAfterAlertShow
{
for (int i = 0; i < [dataArray count]; i++) {
alertMessage = [NSString stringWithFormat:@"Searching... (%d/%d)"
, i, [dataArray count]];
NSLog(@"%@", alertMessage);
// do something here
if (i == [dataArray count]) {
[theAlart dismissWithClickedButtonIndex:0 animated:YES];
}
}
}
并在Alert委托中
- (void)didPresentAlertView:(UIAlertView *)alertView
{
[theAlart setMessage: alertMessage];
}
日志写道:
搜索...(1/8)
搜索...(2/8)
...
搜索...(8/8)
但警报消息在循环结束时发生了变化
答案 0 :(得分:0)
如果操作太快,则关闭动画将比循环本身花费更长的时间。
大多数UI动画都是异步的,因此它们会在后台发生而且不会等待。您可以延迟操作以补偿动画持续时间,或者为NO
dismissWithClickedButtonIndex:animated