您的位置:首页 > 产品设计 > UI/UE

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

2015-04-01 02:57 441 查看
首先要让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 = [UIStoryboard

storyboardWithName:@"Main" bundle:nil];

UIViewController *indexViewController = [mainStoryboard

instantiateViewControllerWithIdentifier:@"IndexViewController"];

indexViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentViewController:indexViewController animated:YES completion:^{

NSLog(@"登录成功!");

}];

}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐