iOS UIActionSheet提示框

本文探讨了一个在iOS应用中使用UIActionSheet时遇到的崩溃问题,并提供了通过改用UIActionSheet来解决该问题的方法。文章详细介绍了如何在ViewController中实现UIActionSheet的显示,以及如何在不同的按钮点击事件中执行相应的操作。

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

之前做过一个项目使用最新的提示框4s会默然的崩溃,于是又修改成最原始的UIActionSheet
UIActionSheet使用情况具体如下

#import "ViewController.h"
@interface ViewController ()<UIActionSheetDelegate>
@property (nonatomic, strong)UIButton *button;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.button = [[UIButton alloc]init];
    self.button.frame = CGRectMake(100, 100, 50, 30);
    self.button.backgroundColor = [UIColor redColor];
    [self.button addTarget:self action:@selector(clicks:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.button];

}

- (void)clicks:(UIButton *)button {

    UIActionSheet* actionSheet = [[UIActionSheet alloc]
                                initWithTitle:@"请选择文件来源"
                                delegate:self
                                cancelButtonTitle:@"取消"
                                destructiveButtonTitle:nil
                                otherButtonTitles:@"照相机",@"摄像机",@"本地相簿",@"本地视频",nil];
                                [actionSheet showInView:self.view];
}


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (buttonIndex) {
        case 0:
        {
           NSLog(@"2");
        }
            break;
        case 1:
            {
           NSLog(@"2");
        }
            break;
        case 2:
            {
           NSLog(@"2");
        }
            break;
        case 3:
        {
            NSLog(@"4");
        }
            break;
        default:
            break;
    }
}

在对应的case中做相应的操作即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值