这就是我创建警报的方式:
UIAlertView* dialog = [[UIAlertView alloc] init];
dialog.delegate = self;
//some options
aField = [[UITextField alloc]initWithFrame:CGRectMake(20.0,45.0,245.0,25.0)];
[aField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:appkeyField];
[dialog show];
[aField release];
但是
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"test here");
}
什么都不做。日志里什么都没有!有什么问题吗?
最佳答案
当您设置对象的delegate 属性时,您的类必须采用适当的协议(protocol)。在您的例子中,您使用的是 UIAlertView,因此您需要将 UIAlertViewDelegate 协议(protocol)添加到头文件中:
@interface MyClass : UIViewController <UIAlertViewDelegate>
要添加多个协议(protocol),请使用:
@interface MyClass : UIViewController <Protocol1, Protocol2, ...>
关于objective-c - UIAlertView clickedButtonAtIndex 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5954255/