0

我是 iOS 开发的新手,所以我觉得我在这里缺少一些基础知识。

我有显示来自服务器的一些信息的视图控制器 (VC)。我的 VC 有两个通知中心观察者——一个用于服务器的成功响应,一个用于错误。

我添加了这样的观察者

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(getPlaceInfoFailed:)
                                                 name:kGetPlaceInfoRequestDidFailBlockNotification
                                               object:nil];

如果出现错误,我想显示警报并导航到上一个视图控制器。让我们将它们命名为视图控制器AB.

我正在使用故事板。

我的问题是,当我返回AUI 时完全搞砸了 - 导航栏有随机的东西,我的表格视图有垃圾等等。最终应用程序崩溃。

以下是我试图解雇我的 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 线程中调用 - 没有区别。

我究竟做错了什么 ?

谢谢!!!

4

2 回答 2

0

看起来我的问题是我performSegueWithIdentifier之前打过电话viewDidAppear,这就是为什么它不起作用。

我如何处理两个异步事件——我还不知道的视图创建和请求服务器。

于 2013-09-02T08:32:20.177 回答
0

我的建议是在通知触发时关闭 VC 并处理父控制器/呈现控制器的 viewWillAppear 中的 UI 事故 - VC A。

如果我没记错的话,这段代码应该在 B 中

- (void)getPlaceInfoFailed:(NSNotification *)notification {
        [self dismissViewControllerAnimated: YES]; or try
        [self dismissModalViewControllerAnimated:YES]; //dep'd in ios 6.


}
于 2013-09-02T07:53:25.517 回答