首页 > 移动平台 > 详细

ios UI 之间的切换方法,using prepareForSegue and not

时间:2015-03-10 06:47:13      阅读:224      评论:0      收藏:0      [点我收藏+]
1, use prepareForSegue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    RWTDetailViewController *detailController =segue.destinationViewController;
    RWTScaryBugDoc *bug = [self.bugs objectAtIndex:self.tableView.indexPathForSelectedRow.row];
    detailController.detailItem = bug;
}

2, use prepareForSegue:
If you want to programmatically invoke a push segue, you give the segue a "storyboard id" in Interface Builder and then you can:
[self performSegueWithIdentifier:"pushToMyVC" sender:self];


3, without prepareForSegue:
Alternatively, if you don‘t want to perform the segue, you can instantiate the destination view controller and then manually push to that view controller. All you need to do is to make sure that the destination view controller has its own "storyboard id" in Interface Builder, then you can:

UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"DestinationController"];
[self.navigationController pushViewController:controller animated:YES];

You said "push" (and hence I used pushViewController above). If you really meant to "present a modal view controller", then that second line is:

[self presentViewController:controller animated:YES completion:nil];

As you can see, you don‘t have to use prepareForSegue to push to new scene. You only use prepareForSegue if you want to pass information to the destination view controller. Otherwise it is not needed.
Clearly, if you‘re not using storyboards (e.g., you‘re using NIBs), then the process is entirely different. But I assume you‘re not using NIBs because prepareForSegue is not applicable in that environment. But if you were using NIB, it would be as follows:

SecondViewController *controller = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];

 
 

ios UI 之间的切换方法,using prepareForSegue and not

原文:http://www.cnblogs.com/welhzh/p/4324978.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!