MyAlertViewActionSheet

本文介绍如何在iOS应用中使用Objective-C实现警告框和操作表,包括创建按钮、设置动作及处理用户交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//
//  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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值