UIAlertView clickedButtonAtIndex is not called
this is how I create the alert:
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];
However
- (void)alertView:(UIAlertView *)alertView
clicked开发者_JS百科ButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"test here");
}
does nothing. There is nothing in the log! What could be wrong?
When you set the delegate
property of an object, your class must adopt the appropriate protocol. In your case, you are using a UIAlertView
, so you need to add the UIAlertViewDelegate
protocol to your header file:
@interface MyClass : UIViewController <UIAlertViewDelegate>
To add multiple protocols, use:
@interface MyClass : UIViewController <Protocol1, Protocol2, ...>
精彩评论