当前位置:编程学习 > wap >>

iphone开发 UIActionSheet(操作表) 和UIAlertView(警告)的用法

一.UIActionSheet(操作表) 和UIAlertView(警告)
 
UIActionSheet用于迫使用户在两个或更多的选项之间进行选择的模式视图。操作表从屏幕底部弹出,显示一系列按钮供用户选择,用户只有单击一个按钮后才能继续使用应用程序。
UIAlertView警告以蓝色圆角矩形形式出现在屏幕中部,警报可显示一个或多个按钮
为了让控制器类充当操作表的委托,控制器需要遵从UIActionSheetDelegate协议
 
二.UIActionSheet(操作表)的创建
 
initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:
 
注释:initWithTitle是对象函数
            initWithTitle:操作表标题
            delegate:接收对象
     cancelButtonTitle关闭按钮标题
            destructiveButtonTitle: 操作按钮标题
            otherButtonTitles:其他按钮
 
1.   创建一个简单的操作表:
    //open a dialog with an OK and cancel button
    UIActionSheet*actionSheet = [[UIActionSheet alloc] 
                  initWithTitle:@" UIActionSheet<title>"
                   delegate:self  
                  cancelButtonTitle:@"Cancel"
                  destructiveButtonTitle:@"OK"
                    otherButtonTitles:nil];
 
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
 
    [actionSheetshowInView:self.view]; //show from our table view (pops up in the middle of the table)
 
    [actionSheetrelease];

\

2.    创建两个按钮的操作表

            // open a dialog with an OKand cancel button

    UIActionSheet*actionSheet = [[UIActionSheet alloc]

                   initWithTitle:@" UIActionSheet<title>"

                    delegate:self

                   cancelButtonTitle:@"Cancel"

                    destructiveButtonTitle:@"OK"

                   otherButtonTitles:nil];

 

    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;

    [actionSheetshowInView:self.view]; //show from our table view (pops up in the middle of the table)

    [actionSheetrelease];

 \

3.   创建自定义操作表:

 

    //open a dialog with two custom buttons

    UIActionSheet*actionSheet = [[UIActionSheet alloc]

                   initWithTitle:@" UIActionSheet<title>"

                    delegate:self

                   cancelButtonTitle:nil

                    destructiveButtonTitle:nil

                otherButtonTitles:@"Button1", @"Button2", nil];

 

    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;

 

    actionSheet.destructiveButtonIndex = 1; // make the second button red(destructive)

 

    [actionSheetshowInView:self.view]; //show from our table view (pops up in the middle of the table)

 

   [actionSheet release];

 \

对操作表中按钮的操作用UIActionSheetDelegate协议函数,这里你可以控制在点击按钮之后的操作

#pragma mark - UIActionSheetDelegate

 

- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

{

    //the user clicked one of the OK/Cancel buttons

    if(buttonIndex == 0)

    {

        //NSLog(@"ok");

    }

    else

    {

        //NSLog(@"cancel");

    }

}

三.UIAlertView(警告)的创建

 

      initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:

   注释:initWithTitle是对象函数

               initWithTitle:警告框标题

               message:警告内容

               delegate:接收对象

               cancelButtonTitle:关闭按钮标题

               otherButtonTitles:其他按钮

 

1.    创建一个简单的警告框

 

    //open an alert with just an OK button

    UIAlertView*alert = [[UIAlertView alloc]

                           initWithTitle:@"UIAlertView"

                          message:@"<Alertmessage>"

                        delegate:self

                           cancelButtonTitle:@"OK"

                           otherButtonTitles: ni

补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,