//
// ViewController.m
// MyAlertViewActionSheet
//
// Created by sunlihuo on 15/5/18.
// Copyright (c) 2015年 sunlihuo. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self onCreate];
}
- (void)onCreate{
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(60, 60, 60, 30);
[btn setTitle:@"更多" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(doMore:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
UIButton *btnAlert = [UIButton buttonWithType:UIButtonTypeSystem];
btnAlert.frame = CGRectMake(200, 60, 60, 30);
[btnAlert setTitle:@"警告" forState:UIControlStateNormal];
[btnAlert addTarget:self action:@selector(doAlert:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnAlert];
}
- (void)doMore:(UIButton *)sender{
NSLog(@"###########");
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"请选择:" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"删除" otherButtonTitles:@"复制", @"剪切", @"粘贴", nil];
[actionSheet showInView:self.view];
}
#pragma mark 警告窗口
- (void)doAlert:(UIButton *)sender{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"标题" message:@"这是消息" delegate:self cancelButtonTitle:@"朕知道了" otherButtonTitles:@"好吧",@"也许", nil];
[alert show];
}
#pragma mark 操作表的委托方法,点击操作表中按钮调用的委托方法
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%zi", buttonIndex);
}
#pragma mark 警告窗口的委托方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%zi", buttonIndex);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
08-14
08-14