【问题标题】:How to Open a UIViewController on Click of UIButton In UIView如何在 UIView 中单击 UIButton 打开 UIViewController
【发布时间】:2014-04-10 13:02:16
【问题描述】:

我想在 UIView 内点击 UIButton 打开一个 UIViewController。 UIView 有它自己的 .h & .m 文件 & 按钮的动作属性在其中声明。

如果我从 UIbutton 的 UIViewController 调用导航代码,它可以正常工作,就像

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
FilterDemoTableViewController *viewController = (FilterDemoTableViewController*)     [mainStoryboard instantiateViewControllerWithIdentifier:  @"FilterDemoTableViewController_Id"];
[[self navigationController]pushViewController:viewController animated:YES];

但是如果从 UIView .m 文件调用相同的代码,那么它不起作用请帮助我。

【问题讨论】:

    标签: ios uibutton uistoryboard


    【解决方案1】:

    它不会。您不能在 UIView 中调用 [self navigationController],因为它没有。

    您所要做的就是引用拥有您的UIView 的ViewController 并在那里调用一个方法。

    通常,您可以使用 NSNotification 来实现 - 这不是最好的方法,但绝对有效。

    【讨论】:

      猜你喜欢
      • 2014-05-21
      • 1970-01-01
      • 1970-01-01
      • 2018-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-26
      相关资源
      最近更新 更多