【问题标题】:How can you tell an UIViewController that a button is pressed in an UIPopOverController?如何告诉 UIViewController 在 UIPopOverController 中按下了按钮?
【发布时间】:2011-04-27 18:03:57
【问题描述】:

我认为标题是自我解释的。 我有一个 UIPopOverController,它是一个表格视图,当我选择一个单元格时,我想告诉它 UIViewController。

有简单的解决方案还是我需要 KeyValueObserving 或通知?

【问题讨论】:

    标签: iphone uiviewcontroller uipopovercontroller


    【解决方案1】:

    从 tableview 发布 NSNotification 并将 UIViewController 添加为观察者。

    【讨论】:

    • 认为这是最简单的方法。
    【解决方案2】:

    您可以根据自己的选择使用两种方法之一移动。

    首先:使用委托/协议。 http://www.thepensiveprogrammer.com/2010/05/objective-c-protocols-and-delegates.html

    第二个:将你的 UIViewController 设置为你的 UIButton 的目标。

    例如

    [btn addTarget:myController action:@selector(ActionWillBePerformedInController:) forControlEvents:UIControlEventTouchUpInside];
    

    【讨论】:

      【解决方案3】:

      发布一个 NSNotification 会很好......你也可以在你的 UITableViewController 类中创建一个回调对象和选择器。

      你可以用回调对象和回调选择器初始化你的 UITableViewController

      initWithTarget:(id)theTarget andSelector:(SEL) theSelector
      

      ...将值保存到属性中

      然后从你的 tableView 中的 didSelectRowAtIndexPath... 调用

      [self.target performSelector:self.selector];
      

      使用这种方法,您可以根据需要定义自己的回调方法。从创建弹出框的 ViewController 类中,您可以执行类似的操作...

      [[MyTableView alloc] initWithTarget:(self) andSelector:@selector(popoverControllerDidRequestClose)];
      

      【讨论】:

        猜你喜欢
        • 2017-05-14
        • 1970-01-01
        • 2018-06-22
        • 1970-01-01
        • 1970-01-01
        • 2014-01-27
        • 1970-01-01
        • 2022-11-17
        • 1970-01-01
        相关资源
        最近更新 更多