UIAlertView点击确定后,如何跳转到storyboard中创建的另一个UIViewController?

来源:互联网 发布:淘宝联盟的导购推广位 编辑:程序博客网 时间:2024/05/17 04:07

首先要让button所在的ViewController类实现UIAlertView的UIAlertViewDelegate接口,接口中定义了一些方法,其中

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;



这个方法会在AlertView中的button被点击时被调用,自己可以根据buttonIndex调用不同的方法,
cancel默认是0,所以如果你的alertview只有一个button的话,实现点击确定后的跳转,

 

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{if (alertView.tag == 1) {[self segue];}}



 

其中tag相当于alertview的标签,可以通过[alertview setTag:]方法设置,用来区别同一ViewController中的多个AlertView对象,根据我的尝试,似乎默认都为0.

segue为自定义的实现跳转的方法。


-(void)segue{UIStoryboard *mainStoryboard = [UIStoryboardstoryboardWithName:@"Main" bundle:nil];UIViewController *indexViewController = [mainStoryboardinstantiateViewControllerWithIdentifier:@"IndexViewController"];indexViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;[self presentViewController:indexViewController animated:YES completion:^{NSLog(@"登录成功!");}];}

 

0 0
原创粉丝点击