0

如果用户在我的 上按 OK,我想记录alertView,但它什么也没做......这是我的支票:

- (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但也不会被记录下来..

谢谢

4

3 回答 3

3

而不是委托为零,将您的委托分配为自己

于 2013-10-02T10:37:11.233 回答
2

使用以下内容:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oeps..."
                                        message:@"This is just a random message."
                                        delegate:self
                                        cancelButtonTitle:@"OK"
                                        otherButtonTitles:nil];
[alertView show];
于 2013-10-02T10:40:46.610 回答
1

检查您的委托,您将委托传递给 nil。把它传给自己,这就是为什么会发生这种情况......

像这样

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oeps..."
                                            message:@"This is just a random message."
                                            delegate:self
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];
[alertView show];
于 2013-10-02T10:45:06.187 回答