zoukankan      html  css  js  c++  java
  • 警告框和操作表(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];
    }
    


  • 相关阅读:
    学生管理系统初步总结
    ListView控件详解
    Windows窗体应用布局详解
    winforms控件
    指尖上的数据库之探囊取物
    指尖上的数据库之无中生有
    银行bank系统项目实践
    QT Creator 快速入门教程 读书笔记(一)
    我的程序员之路(英语的学习)
    游戏开发完整学习路线(各个版本都有)
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4088684.html
Copyright © 2011-2022 走看看