Art*_*gul 2 iphone cocoa-touch uialertview
在下面的示例代码UIAlertView是延迟后显示,但我需要立即显示它
//metoda zapisuje komentrz na serwerze
-(void) saveAction {
UIAlertView *progressAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"imageGalleries.sendAction", @"") message:@" " delegate:self cancelButtonTitle:NSLocalizedString(@"alert.cancel", @"") otherButtonTitles:nil];
[progressAlert addSubview:progressView];
[progressAlert show];
// some long performance instructions
}
- (void)loadView {
[super loadView];
self.navigationItem.rightBarButtonItem = [NavButton buttonWithTitle:NSLocalizedString(@"sendImage.saveButtonTitle", @"") target:self action:@selector(saveAction)];
progressView = [[UIProgressView alloc] initWithFrame: CGRectMake(30.0f, 80.0f - 26, 225.0f, 10.0f)];
}
Run Code Online (Sandbox Code Playgroud)
UIAlertView我打电话时为什么不立即显示saveAction?
zou*_*oul 10
如果警报代码后面的"长性能指令"在主线程上运行,它们将阻止警报出现.阅读有关Cocoa运行循环的内容,这应该会让事情变得更加清晰.(基本上可以说你的方法中的所有UI指令都没有立即执行 - 他们必须等待方法结束,然后主运行循环选择并运行它们.)
代码可能看起来更像这样:
- (void) startSomeLongOperation {
[self createAndDisplayProgressSpinner];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_NORMAL, 0), ^{
// …do something that takes long…
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissProgressSpinner];
});
});
}
Run Code Online (Sandbox Code Playgroud)
这会将长操作移到后台,以便主线程可以立即继续执行.
| 归档时间: |
|
| 查看次数: |
2915 次 |
| 最近记录: |