AlertView ClickedButtonAtIndex不起作用

时间:2015-10-25 00:18:02

标签: ios objective-c uialertview

我已阅读相关帖子,但由于点击了我的提醒上的“确定”按钮后未调用ClickedButtonAtIndex方法,因此必须遗漏某些内容。我在ClickedButtonAtIndex方法中设置了一个断点,它永远不会到达,并且永远不会执行NSLog。

这里是.h代码:

#import <UIKit/UIKit.h>

@interface MainPage : UIViewController <UIAlertViewDelegate> {
    IBOutlet UILabel *sendtxtlabel;
}

- (IBAction)button:(id)sender;
@end

这里是.m代码:

@interface MainPage ()

@end

@implementation MainPage

- (void)viewDidLoad {
    [super viewDidLoad];

    sendtxtlabel.text= [NSString stringWithFormat:@"Number 800-555-1212"];

    // Do any additional setup after loading the view.

    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Vehicle Owner"
                          message:@"Enter Phone Number"
                          delegate:self
                          cancelButtonTitle:@"Cancel"
                          otherButtonTitles:@"ok", nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    alert.tag =12;
    //[alert addButtonWithTitle:@"ok"];
    [alert show];
    NSLog(@"ok");


}



- (void) alertView: (UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    // Capture the phone number input from the alert pop-up window. UIAlertView Delegate added to allow the OS trigger this method to read the data.

    if (alertView.tag == 12) {
        if (buttonIndex == 1) {
            UITextField *textfield = [alertView textFieldAtIndex:0];
            NSLog(@"phonenumber: %@", textfield.text);

        }

    }

}

0 个答案:

没有答案