代码之家  ›  专栏  ›  技术社区  ›  Forrest

使用uiAlertViewDelegate示例了解协议实现

  •  0
  • Forrest  · 技术社区  · 16 年前

    有两个等级A和B:

    @接口A:nsObject<uiAlertViewDelegate>…}结束

    @接口B…}

    A将通过创建B来使用B并使用它。

    在B中,有机会创建uialertviewdialog,并进行一些用户交互。

    我认为在类A中实现ClickedButtonatindex是合理的,因为声明a是为了确认uiAlertViewDelegate。但事实是我们应该在B中实现。

    • (void)警报视图:(uialertview*)警报单击按钮索引:(nsinteger)按钮索引 //bla bla_

    我真的不明白什么才是确认这种协议的真正原因。

    提前谢谢。

    1 回复  |  直到 16 年前
        1
  •  1
  •   Shingoo    16 年前

    UIAlertView *alert = [[UIAlertView alloc]
              initWithTitle: title
              message: message
              delegate: delegate
              cancelButtonTitle: firstButtonName
              otherButtonTitles: nil];
    

    因此,如果您在类B中创建uialertview,但是您想要在类A中的按钮点击上做出反应,那么您需要将上面代码中的委托设置为类A。