Ios 要在用户单击“完成”后调用presentingViewController中的方法吗

Ios 要在用户单击“完成”后调用presentingViewController中的方法吗,ios,uiviewcontroller,Ios,Uiviewcontroller,Noobie iOS开发者在这里采用了iOS应用程序 我有一个iOS应用程序的设置部分,当用户单击“完成”时,我想要模态视图控制器(它当前正在使用),我想要在presentingViewController中调用名为UpdateManui的函数 下面是我调用的方法: - (void)done:(id)sender { [[self presentingViewController] dismissViewControllerAnimated:YES completion:nil]; // w

Noobie iOS开发者在这里采用了iOS应用程序

我有一个iOS应用程序的设置部分,当用户单击“完成”时,我想要模态视图控制器(它当前正在使用),我想要在presentingViewController中调用名为UpdateManui的函数

下面是我调用的方法:

- (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;

在解雇了一个
self
之后,您应该期望
self.presentingViewController
变成
nil
。在解除之前尝试调用
updateMainUI

[[self-presentingViewController updateMainUI]
已损坏且无法编译。假设您的意思是
[[self-presentingViewController]updateMainUI]
,那么还有其他方法可以做到这一点

LocationsViewController *presenting = (LocationsViewController *)[self presentingViewController];
[presenting dismissViewControllerAnimated:YES completion:^{
    [presenting updateMainUI];
}];

使用变量表示是一个重要的步骤。

Crud,我现在看到了真正的答案。这是一个铸造问题。尝试以下方法:

[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
[(LocationsViewController *)[self presentingViewController] updateMainUI];

您需要非常确定
-presentingViewController
返回类型为LocationsViewController的对象,否则您将面临更大的问题。

thx…嗯…仍然会出现错误。我应该能够像我这样调用实例方法吗?是的,您应该能够,您可以尝试的一件事是强制转换预处理将ViewController设置为您的类名。如果我记录presnetingViewController,它会告诉我它是一个UIAbbarController-但显示视图控制器应该是UIAbbarController中的UINavigationController中的UIAbbarController-我可能不明白[自显示视图控制器]是如何实现的正在工作。我真的只想引用即时控制器。Apple文档:如果接收此消息的视图控制器由另一个视图控制器呈现,则此属性将保留呈现它的视图控制器。如果未呈现视图控制器,但呈现它的一个祖先,则此属性将保留v视图控制器显示最近的祖先。如果视图控制器或其任何祖先都未显示,则此属性为零。==>因此,不是您的表视图显示模式视图控制器,而是第一个可以处理它的父视图。确定-因此,我更新了上面的edit#1-不完全确定如何获得此cont滚动参考。如果有任何帮助,我们将不胜感激。是的,我有其他方法,但为?-will update进行了编辑。嗯……因此,我肯定缺少有关presentingViewController的某些内容,因为我在编译修复程序时出错:
不兼容指针类型初始化“LocationsViewController*\uu strong”,并使用类型为“U”的表达式IViewController*”
OK,只要您非常确定该类型,就将其强制转换为
LocationsViewController*presenting=(LocationsViewController*)[self-presentingViewController];
问题在于presentingViewController!=实例化它的视图控制器。呃…嗯…但是presentingViewController仍然作为UITabBarController而不是LocationsViewController返回。我尝试导航ViewController数组,但没有导航到avial。我不敢相信这有多复杂:-(此链接提供了解决方案:您找到答案了吗?我也有同样的问题。我在
选项卡栏中调用了
navgationcontroller
作为模式视图。现在
presentingViewController
属性正在返回对
UITabBar
的引用。
[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
[(LocationsViewController *)[self presentingViewController] updateMainUI];