警告框和操作表(IOS开发)

警告框(AlertView)时模态的,不关闭它就不能做其它事情,所以不是下面几种情况不应该随便使用。

1、应用不能继续执行。

如内存不足,没有网络。一般仅仅须要一个button。

2、询问还有一个解决方式。

不能执行时,询问能否够用3G网络。

3、询问对操作的授权。

涉及到訪问隐私信息的时候,须要用户授权,如位置、相冊等。


操作表(ActionSheet)能够给用户提供多个选择。能够利用它将某个图片发给新浪微博或者Facebook平台。

/ 实现UIAlertViewDelegate
// 这个托付事实上没实用到,就当练练手,由于警告窗体有两个按钮索引
// No为0,Yes为1
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"buttonIndex = %li", (long)buttonIndex);
}

// 实现UIActionSheetDelegate
// 这个托付也没有实际意义,就是在输出命令窗体输出按下的索引数,以实现响应
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"buttonIndex = %li", (long)buttonIndex);
}

- (IBAction)testAlertView:(id)sender {
    // 警告框在上文已叙述
    // delegate 參数用于设置该警告窗体的托付对象
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert"
                                                message: @"Alert text goes here"
                                                delegate:self cancelButtonTitle:@"No"
                                              otherButtonTitles:@"Yes",
                              nil];
    [alertView show];
    
}

- (IBAction)testActionSheet:(id)sender {
    // cancelButtonTitle 设置取消标题
    // destructiveButtonTile 设置破坏型按钮,仅仅能有一个在最上面
    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:nil
                                  delegate:self
                                  cancelButtonTitle:@"取消"destructiveButtonTitle:@"破坏性按钮"
                                  otherButtonTitles:@"新浪微博", nil];
    // 设置为自己主动样式
    actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
    [actionSheet showInView:self.view];
}


转载于:https://www.cnblogs.com/lcchuguo/p/4088684.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值