如果用户在alertView
上按了OK,我想记录,但它什么也没做......这是我的检查:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) { NSLog(@"user pressed OK"); }
}
也在我的@interface
:
@interface FirstViewController : UIViewController<UIWebViewDelegate, UIAlertViewDelegate>
这是我的alertView
:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oeps..."
message:@"This is just a random message."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
有没有人看到这个问题?我试图在NSLog
之外做if buttonIndex
,但也不会记录..
由于
答案 0 :(得分:3)
而不是委托为nil,将您的委托指定为自己
答案 1 :(得分:2)
使用以下内容:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oeps..."
message:@"This is just a random message."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
答案 2 :(得分:1)
检查您将代表传递给nil的代表。将它传递给自我,这就是发生这种情况......
像这样UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oeps..."
message:@"This is just a random message."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];