.h代码如下@interface demo4ViewController : UIViewController 
<UIAlertViewDelegate>{}-(IBAction)myclick:(id)sender;
.m代码如下-(IBAction)myclick:(id)sender
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:@"option 1",@"option2",nil];
[alert show];
}-(void)alertView:(UIAlertView *)alertView buttonAtIndex:(NSInteger)buttonIndex{
NSLog([NSString stringWithFormat:@"%d",buttonIndex]);
}为什么运行了以后控制台不输出东西??根本就进不了alertView方法.怎么办?

解决方案 »

  1.   

    -(void)alertView:(UIAlertView *)alertView buttonAtIndex:(NSInteger)buttonIndex{
        NSLog([NSString stringWithFormat:@"%d",buttonIndex]);
    } 这个里面只有一个log 输出你想有什么反应
      

  2.   

    找到问题了, (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
    貌似方法必须叫这个名字
      

  3.   

    呵呵,必须的。这是UIAlertViewDelegate协议中的方法,你只需要实现。