想要在用户点击完成后调用showsViewController中的方法
Noobie iOS开发人员在这里采用了iOS应用程序。
我有一个iOS应用程序的设置部分,当用户点击完成时,我想要模态视图控制器(它目前正在做),我想在presentViewController中调用一个名为updateMainUI的函数。
这是我打电话的方法:
- (void)done:(id)sender { [[self presentingViewController] dismissViewControllerAnimated:YES completion:nil]; // works [[self presentingViewController updateMainUI]; //doesn't work
但是我收到以下错误:
No visible @interface for 'UIViewController' declares the selector 'updateMainUI'
但我已在演示控制器中声明了这一点
@interface LocationsViewController : UITableViewController -(void)updateMainUI;
但是当呈现控制器是UITableViewController时,错误应该是关于UIViewController的,这很奇怪。
有关如何使updateMainUI工作的任何想法? 我做错了什么?
谢谢
编辑#1这就是我创建这个的方法 – 任何想法如何引用* nearbyViewController?
UIViewController *nearbyViewController = [[LocationsViewController alloc] initWithNearbyLocations]; UINavigationController *nearbyNavigationController = [[UINavigationController alloc] initWithRootViewController:nearbyViewController]; ... self.tabBarController = [[UITabBarController alloc] init]; self.tabBarController.viewControllers = [NSArray arrayWithObjects:nearbyNavigationController, browseNavigationController, eventsNavigationController, nil];
在解雇self
,你应该期望self.presentingViewController
变为nil
。 尝试在解雇之前调用updateMainUI
。
Crud,我现在看到了真正的答案。 这是一个铸造问题。 尝试这个:
[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil]; [(LocationsViewController *)[self presentingViewController] updateMainUI];
您需要非常确定-presentingViewController
返回LocationsViewController类型的对象,否则您手上会遇到更大的问题。
[[self presentingViewController updateMainUI]
已损坏,无法编译。 假设你的意思是[[self presentingViewController] updateMainUI]
,那么还有其他方法可以做到这一点。
LocationsViewController *presenting = (LocationsViewController *)[self presentingViewController]; [presenting dismissViewControllerAnimated:YES completion:^{ [presenting updateMainUI]; }];
使用变量呈现是重要的一步。