2010-06-25 111 views
0

有两种类A和B:理解协议实现与例如UIAlertViewDelegate

@interface答:NSObject的< UIAlertViewDelegate> {...} @end

@interface B {...}

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

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

我认为在类A中实现clickedButtonAtIndex是合理的,因为A被声明为确认UIAlertViewDelegate。但是,真正的是,我们应该在B.实现

  • (无效)alertView:(UIAlertView中*)警报clickedButtonAtIndex:(NSInteger的)buttonIndex {//喇嘛喇嘛}

我真的不明白什么是真正的原因来确认这种情况下的协议。

在此先感谢。

回答

1

在创建UIAlertView中定义会是怎样的委托类:

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

所以,如果你在B类创建的UIAlertView中,但你要在A类,你需要设置按钮自来水发生反应在代码上面的代码A级。

+0

感谢您的回答,这清除了我的困惑。 – Forrest 2010-06-29 05:51:50

+0

如果您可以接受答案(通过点击勾号),如果这是您正在查找的信息,那将会很棒;) – Shingoo 2010-06-29 15:48:46