| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
fmms
13年前发布

Iphone对话框工具类

在项目中我把对话框的弹出与点击事件通过一个工具类给封装起来了,重要的是要在调用这个工具类的时候实现工具类中的协议,这个协议的方法是为了告诉页面到底点击了哪种对话筐的哪一个button,然后页面中可以根据传过去的不同值做出不同的事件响应,代码如下:

.h文件

    #import <Foundation/Foundation.h>                @protocol myAlertviewutilDelegate <NSObject>                -(void)myalertviewbuttonclik:(int)num;                @end                @interface AlertViewUtil : NSObject<UIAlertViewDelegate> {            //自定义的对话筐协议            id<myAlertviewutilDelegate> utildelegate;            UIAlertView *myonealertview;//一个按钮的对话筐            UIAlertView *mytwoalertview;//两个按钮的对话筐            UIAlertView *mythreealertview;//三个按钮的对话筐        }                @property(nonatomic,retain) id<myAlertviewutilDelegate> utildelegate;                        -(void)alertviewutilone:(NSString *)buttontitleone addmessage:(NSString *)message;        -(void)alertviewutiltwo:(NSString *)buttontitleone twobutton:(NSString *)buttontitletwo addmessage:(NSString *)message;        -(void)alertviewutilthree:(NSString *)buttontitleone twobutton:(NSString *)buttontitletwo threebutton:(NSString *)buttontitlethree addmessage:(NSString *)message;        @end  
.m文件
    #import "AlertViewUtil.h"                        @implementation AlertViewUtil        @synthesize utildelegate;                -(void)dealloc{            [utildelegate release];            [super dealloc];        }        //实现系统对话筐协议中的button点击方法        - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{            //点击的是第一个alertview            if (alertView == myonealertview) {                if (buttonIndex == 0) {                    [self.utildelegate myalertviewbuttonclik:11];                }                    [myonealertview release];            }            //点击的是第二个alertview            else if (alertView == mytwoalertview) {                if (buttonIndex == 0) {                      [self.utildelegate myalertviewbuttonclik:21];                }                else if(buttonIndex == 1){                    [self.utildelegate myalertviewbuttonclik:22];                }                [mytwoalertview release];            }            //点击的是第三个alertview           else if (alertView == mythreealertview) {                if (buttonIndex == 0) {                    [self.utildelegate myalertviewbuttonclik:31];                }                else if(buttonIndex == 1){                    [self.utildelegate myalertviewbuttonclik:32];                }                else if(buttonIndex == 2){                    [self.utildelegate myalertviewbuttonclik:33];                }                                        [mythreealertview release];            }                     }                //只有一个按钮 的alertview        -(void)alertviewutilone:(NSString *)buttontitleone addmessage:(NSString *)message{            myonealertview = [[UIAlertView alloc]initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:nil otherButtonTitles:buttontitleone, nil];            [myonealertview show];        }                //两个按钮 的alertview        -(void)alertviewutiltwo:(NSString *)buttontitleone twobutton:(NSString *)buttontitletwo addmessage:(NSString *)message{            mytwoalertview = [[UIAlertView alloc]initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:nil otherButtonTitles:buttontitleone,buttontitletwo, nil];            [mytwoalertview show];        }                //三个按钮 的alertview        -(void)alertviewutilthree:(NSString *)buttontitleone twobutton:(NSString *)buttontitletwo threebutton:(NSString *)buttontitlethree addmessage:(NSString *)message{            mythreealertview = [[UIAlertView alloc]initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:nil otherButtonTitles:buttontitleone,buttontitletwo,buttontitlethree, nil];            [mythreealertview show];        }                @end  

 本文由用户 fmms 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1335678327202.html
iPhone iOS开发 移动开发