学习UIAlertView和UIActionSheet

1、定义文件定义事件

@interface ViewController : UIViewController<UIAlertViewDelegate,UIActionSheetDelegate>

- (IBAction)btnAlertView:(id)sender;

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

2、实现文件实现事件

- (IBAction)btnAlertView:(id)sender {
    UIAlertView *alertView = [[UIAlertView  alloc]initWithTitle:@"这是标题" message:@"这是内容" delegate:self cancelButtonTitle:@"取消按钮" otherButtonTitles:@"其他按钮",@"其他按钮2",nil];
    [alertView show];
}

- (IBAction)btnActionSheet:(id)sender {
    UIActionSheet *actionSheet =[[UIActionSheet alloc]initWithTitle:@"这是标题" delegate:self cancelButtonTitle:@"取消按钮" destructiveButtonTitle:@"破坏性按钮" otherButtonTitles:@"其他1",@"其他2",@"其他3", nil];
    [actionSheet showInView:self.view];
}

3、相关事件 

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"点击按钮索引:%i",buttonIndex);
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    NSLog(@"点击按钮索引:%i",buttonIndex);
}

 

posted on 2014-12-01 22:32  兔儿爷  阅读(73)  评论(0)    收藏  举报

导航