/*@interface AppDelegate : UIResponder <UIApplicationDelegate,UIAlertViewDelegate,UIActionSheetDelegate>代理*/
//创建两按钮及其目标
UIButton *b1=[[UIButton alloc]initWithFrame:CGRectMake(30, 60, 120, 60)];
b1.backgroundColor=[UIColor greenColor];
[b1 setTitle:@"警报" forState:UIControlStateNormal];
[b1 addTarget:self action:@selector(alertTap:) forControlEvents:UIControlEventTouchUpInside];
UIButton *b2=[[UIButton alloc]initWithFrame:CGRectMake(180, 60, 120, 60)];
b2.backgroundColor=[UIColor greenColor];
[b2 setTitle:@"操作表" forState:UIControlStateNormal];
[b2 addTarget:self action:@selector(actionTap:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:b1];
[self.window addSubview:b2];
return YES;
}
//实现目标 创建警报视图
-(void)alertTap:(id)sender
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"警告" message:@"你当前在浏览非法网站,请立即退出" delegate:self cancelButtonTitle:@"好" otherButtonTitles:@"否", nil];
[alert show];
}
//警报按键所对应的位置
-(void)alertView:(nonnull UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==0)
NSLog(@"你点击了好");
else if(buttonIndex==1)
NSLog(@"你点击了否");
}
//创建操作表视图
-(void)actionTap:(id)sender
{
UIActionSheet *action=[[UIActionSheet alloc]initWithTitle:@"删除?" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"销毁" otherButtonTitles:@"其他", nil];
//操作表视图显示的方法略有不同
[action showInView:self.window];
}
//操作表视图按键所对应的位置
-(void)actionSheet:(nonnull UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==0)
NSLog(@"你选择了销毁");
else if(buttonIndex==1)
NSLog(@"你选择了其他");
else if (buttonIndex==2)
NSLog(@"你选择了取消");
}