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

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

1、应用不能继续运行。

如内存不足,没有网络。一般只需要一个按钮。

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];
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值