2012-08-14 67 views
0

忽略TextField,因爲buttonIndex不起作用,所以我離開文本字段的語法。AlertView ButtonIndex不工作

-(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"); 
} 
} 

回答

-1

嘗試使用alertview.cancelButtonIndex或alertview.firstOtherButtonIndex而不是0這將是比使用幻數更具有可讀性。

+0

工作謝謝! – 2012-08-14 01:47:38

1

您是否將<UIAlertViewDelegate>添加到頭文件?

@implementation MyClass : <UIAlertViewDelegate>