关于UIAlertView使用的一些注意事项
首先我们要支持协议,在.h文件内添加协议
#import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIAlertViewDelegate> @property(retain,nonatomic)UIAlertView *alertV,*alertV2;
我们在对提示框内各按键进行设定时,要注意,如果一个case里面有多句,要加上{}
//设置提示窗口的各按钮的功能 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ //如果有多个提示窗口,那么不同提示窗口的按钮功能可能不用,这时候要判断一下是哪个提是窗口,再对哪个提示窗口进行我们需要对它实现的功能 if (alertView==self.alertV) { switch (buttonIndex) { case 0: { //注意不只一句的时候要加{} //跳转界面 MainViewController* fanhui=[[[MainViewController alloc]init]autorelease]; [self presentViewController:fanhui animated:YES completion:nil]; break; } case 1: { Lv2ViewController *next=[[[Lv2ViewController alloc]init]autorelease]; [self presentViewController:next animated:YES completion:nil]; break; } default: break; } } else{ switch (buttonIndex) { case 0: { MainViewController *fanhui=[[[MainViewController alloc]init]autorelease]; [self presentViewController:fanhui animated:YES completion:nil]; break; } case 1: { ViewController *chongshi=[[[ViewController alloc]init]autorelease]; [self presentViewController:chongshi animated:YES completion:nil]; break; } default: break; } } }