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 <CLLocationManagerDelegate, UISearchBarDelegate, UISearchDisplayDelegate>
-(void)updateMainUI;
但是当呈现控制器是UITableViewController时,错误应该是关于UIViewController的。这很奇怪。
有关如何使updateMainUI正常工作的任何想法?我做错了什么?
THX
编辑#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];
答案 0 :(得分:4)
解雇self
后,您应该self.presentingViewController
成为nil
。在解雇之前尝试拨打updateMainUI
。
答案 1 :(得分:1)
Crud,我现在看到了真正的答案。这是一个铸造问题。试试这个:
[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
[(LocationsViewController *)[self presentingViewController] updateMainUI];
你需要非常确定-presentingViewController
返回一个LocationsViewController类型的对象,否则你手上会遇到更大的问题。
答案 2 :(得分:0)
[[self presentingViewController updateMainUI]
已损坏且无法编译。假设你的意思是[[self presentingViewController] updateMainUI]
,那么还有其他方法可以做到。
LocationsViewController *presenting = (LocationsViewController *)[self presentingViewController];
[presenting dismissViewControllerAnimated:YES completion:^{
[presenting updateMainUI];
}];
使用变量呈现是一个重要的步骤。