0

I have a parent view controller that modally presents another view controller. When a button is pressed on the presented view controller, I need to have the parent that is presenting the view controller dismiss the presented view controller and then open up a different view controller. Here is my code after the button is pressed:

//Set up a reference to the parent controller 
FeedViewController* newsFeed = (FeedViewController*)self.presentingViewController;
//Tell it to dismiss the presented view controller
[newsFeed dismissViewControllerAnimated:YES completion:nil];
//Tell it to open up the other view controller 
[newsFeed openNewsCreator];

The problem here is that final line. XCode says that the selector openNewsCreator is unrecognized by newsFeed. I tried setting manually giving the presented view controller a reference to the FeedViewController and it worked fine, so theres nothing missing in my .h file.

I even tried reversing the dismissal and presenting lines like so:

FeedViewController* newsFeed = (FeedViewController*)self.presentingViewController;
[newsFeed openNewsCreator];
[newsFeed dismissViewControllerAnimated:YES completion:nil];

This didn't work either. Any suggestions? Also, here's the error:

reason: '-[UINavigationController openNewsCreator]: unrecognized selector sent to    instance 0x9a61760'
4

1 回答 1

1

错误消息非常明确——您认为是 FeedViewController 的控制器实际上是 UINavigationController。这是因为当您从嵌入在导航控制器中的控制器中呈现控制器时,实际上是导航控制器进行呈现,因此 self.presentingViewController 将成为导航控制器。不知道您的应用程序的结构很难判断,但您需要获得对 FeedViewController 的正确引用。大概是导航控制器的topViewController。

于 2013-11-03T04:23:55.483 回答