ios7_如何实现UIAlertView以及监听点击事件(默认样式)

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

1、在viewController的.m文件,遵守<UIAlertViewDelegate>代理协议

@interfacemoboViewController () <UIAlertViewDelegate>

2、在 - (void)viewDidLoad 方法中实现UIAlertView

1- (void)viewDidLoad2{3[super viewDidLoad];45//1、初始化 alertView6UIAlertView *altView = [[UIAlertView alloc]initWithTitle:[self altTitle] message:[self altMSG]delegate:self cancelButtonTitle:[self cancelBtnTitle] otherButtonTitles:[self otherBtnTitle], nil];7//2、显示 alertView8[altView show];910}

3、继续实现其它方法,返回各种标题以及监听按钮点击事件的代理方法

1//返回 标题2- (NSString *)altTitle{3return@"下线通知";4}56//返回 消息体7- (NSString *)altMSG{8return@"你的帐号在异地登录,密码可能泄露,建议前往http://mobodemy.com进行修改。";9}1011//返回 退出按钮 标题12- (NSString *) cancelBtnTitle {13return@"退出";14}1516//返回 重新登录 按钮标题17- (NSString *) otherBtnTitle {18return@"重新登录";19}2021//监听点击事件 代理方法22- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex23{24NSString *btnTitle =[alertView buttonTitleAtIndex:buttonIndex];25if([btnTitle isEqualToString:[self cancelBtnTitle]]) {26NSLog(@"你点击了退出");27}28elseif([btnTitle isEqualToString:[self otherBtnTitle]] ) {29NSLog(@"你点击了重新登录按钮");30}31}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航