McD*_*cDJ 5 iphone multithreading
我有一个用于在用户单击"保存"时保存图像的方法.我使用performSelectorInBackground来保存图像,弹出viewcontroller并显示前一个viewcontroller.
我希望表(在previousUIViewController上)在完成图像处理时重新加载其数据.
我怎样才能做到这一点?
save方法的调用方式如下:
[self performSelectorInBackground:@selector(saveImage) withObject:nil];
[self.navigationController popViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)
在您的saveImage方法中,在完成保存图像之后和从方法返回之前发布通知.像这样的东西:
// post notification
[[NSNotificationCenter defaultCenter] postNotificationName:@"ImageSaved" object:nil];
Run Code Online (Sandbox Code Playgroud)
在处理表的控制器中,实现
- (void) imageSaved:(NSNotification *)notification{
[self.tableView reloadData];
}
Run Code Online (Sandbox Code Playgroud)
并在其viewDidLoad方法中添加以下代码以注册通知:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(imageSaved:)
name:@"ImageSaved" object:nil];
Run Code Online (Sandbox Code Playgroud)
最后,在dealloc方法添加中取消注册
[[NSNotificationCenter defaultCenter] removeObserver:self];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3265 次 |
| 最近记录: |