我是 iOS 开发的新手,所以我觉得我在这里缺少一些基础知识。
我有显示来自服务器的一些信息的视图控制器 (VC)。我的 VC 有两个通知中心观察者——一个用于服务器的成功响应,一个用于错误。
我添加了这样的观察者
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getPlaceInfoFailed:)
name:kGetPlaceInfoRequestDidFailBlockNotification
object:nil];
如果出现错误,我想显示警报并导航到上一个视图控制器。让我们将它们命名为视图控制器A
和B
.
我正在使用故事板。
我的问题是,当我返回A
UI 时完全搞砸了 - 导航栏有随机的东西,我的表格视图有垃圾等等。最终应用程序崩溃。
以下是我试图解雇我的 VC 的方法B
- (void)getPlaceInfoFailed:(NSNotification *)notification {
dispatch_async(dispatch_get_main_queue(), ^{
//[self.navigationController popViewControllerAnimated:YES];
//[self dismissViewControllerAnimated: YES completion: nil];
//[self.presentingViewController dismissViewControllerAnimated: YES completion: nil];
//[self.presentedViewController dismissViewControllerAnimated: YES completion: nil];
//[self performSegueWithIdentifier:@"exitSegue" sender:self];
});
}
版本[self performSegueWithIdentifier:@"exitSegue" sender:self];
在我调用它时起作用,例如,在按钮操作处理程序中。
但不是在观察者中:(如您所见,我试图performSegue
在 UI 线程中调用 - 没有区别。
我究竟做错了什么 ?
谢谢!!!