六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 1195|回复: 0

ios ViewController 页面跳转

[复制链接]
 楼主| 发表于 2013-11-12 21:55:18 | 显示全部楼层 |阅读模式
从一个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];
结果完美实现跳转。
值得注意是,如果是直接通过按钮的单击事件也能通过segue跳转,并且是一点击按钮,就跳转了。这里需要的是,点击按钮后,经过一定的逻辑后才跳转。就需要上面的实现方式了。

本文摘自:http://blog.csdn.net/yesjava/article/details/7894663

该会员没有填写今日想说内容.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表