从一个Controller跳转到另一个Controller时,一般有以下2种:
1、利用UINavigationController,调用pushViewController,进行跳转;这种采用压栈和出栈的方式,进行Controller的管理。调用popViewControllerAnimated方法可以返回。
PickImageViewController *ickImageViewController = [[PickImageViewController alloc] init];
[self.navigationController pushViewController: ickImageViewController animated:true];
[ickImageViewController release];
2、利用UIViewController自身的presentModalViewController,进行跳转;调用dismissModalViewControllerAnimated方法可以返回。
PickImageViewController *ickImageViewController = [[PickImageViewController alloc] init];
[self presentModalViewController:ickImageViewController animated:YES];
//返回
[self dismissModalViewControllerAnimated:YES];
本文摘自:http://longquan.iteye.com/blog/1666292
做了例子大概是这样字的,第一个页面,是登录页面,有用户名和密码,点击登录按钮,去请求服务器(就是一个jsp),根据输入的参数确定返回结果。若返回结果是ok就跳转到另外一个欢迎页面。我的做法是在storyboard里重新拖拽出一个viewcontroller,在登录的viewcontroller里点击登录按钮,去请求服务器,等结果返回后,写以下代码WelcomeVIewController * welcome=[[WelcomeVIewController alloc] init];
[self presentModalViewController:welcome animated:YES];
悲剧的是,切换到第二个页面却是黑屏。怎么改都不行,搞到晚上12点还是没搞定。 第二天,看到了storyboard介绍的一篇文章,说到了这样一句话“ViewController之间的过渡代码不需要了,用StoryBoard的Segue直接可视化连接不同的ViewController”,就试着把两个viewController连了起来,并且将segue的id叫做“welcome‘。然后在代码里写以下的代码 [self performSegueWithIdentifier "welcome" sender:self];
结果完美实现跳转。
|