Ios AlertView按钮索引不工作

Ios AlertView按钮索引不工作,ios,xcode,uialertview,alertview,Ios,Xcode,Uialertview,Alertview,忽略TextField,因为buttonIndex不起作用,所以我忽略了TextField语法 -(IBAction)bm1:(id)sender { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Set Bookmark" message:@"Type URL Here" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; alert

忽略TextField,因为buttonIndex不起作用,所以我忽略了TextField语法

-(IBAction)bm1:(id)sender {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Set Bookmark" message:@"Type URL Here" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;

                      [alert show];
                      [alert release];
                      }
- (void)alertView:(UIAlertView *)alertview clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
    NSLog(@"It works");
}
}

尝试使用alertview.cancelButtonIndex或alertview.firstOtherButtonIndex而不是0。这将比使用幻数更具可读性。

是否在头文件中添加了

@implementation MyClass : <UIAlertViewDelegate>
@实现MyClass: