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

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];

 
 
时间: 2024-10-04 06:47:45

ios UI 之间的切换方法,using prepareForSegue and not的相关文章

iOS UI 调试工具Reveal破解方法

删除如下文件:(可以继续试用30天) ~/Library/Preferences/com.ittybittyapps.Reveal.plist

IOS关于UIViewController之间的切换

IOS关于UIViewController之间的切换 1.NavigationController切换UIViewController的两种方式 方法一右侧进入 1 SecondViewController* svc=[[SecondViewController alloc]init]; 2 [self.navigationController pushViewController:fvc animated:YES]; 返回到上一个 [self.navigationController popV

iOS 视图在不同View之间的切换(对于convertRect:函数的一些理解)

可以通过以下函数完成坐标体系在不同View之间的切换,如下面是完成当前View向ParentView坐标的转换(一个矩阵转换)CGRect parentRect = [currentView convertRect:blankImageView.bounds toView:self.superview]; (self.view 上有viewA 与 viewB 两个视图 btn在viewA上) 绝对rect =[viewA.superView convertRect:btn.frame fromV

ios7中 丰富多彩的UIViewController之间的切换

转载自:http://onevcat.com/2013/10/vc-transition-in-ios7/ 毫无疑问,ViewController(在本文中简写为VC)是使用MVC构建Cocoa或者CocoaTouch程序时最重要的一个类,我们的日常工作中一般来说最花费时间和精力的也是在为VC部分编写代码.苹果产品是注重用户体验的,而对细节进行琢磨也是苹果对于开发者一直以来的要求和希望.在用户体验中,VC之间的关系,比如不同VC之间迁移和转换动画效果一直是一个值得不断推敲的重点.在iOS7中,苹

iOS开发系列--视图切换

概述 在iOS开发中视图的切换是很频繁的,独立的视图应用在实际开发过程中并不常见,除非你的应用足够简单.在iOS开发中常用的视图切换有三种,今天我们将一一介绍: UITabBarController UINavigationController 模态窗口 UITabBarController iOS三种视图切换的原理各不相同: UITabBarController:以平行的方式管理视图,各个视图之间往往关系并不大,每个加入到UITabBarController的视图都会进行初始化即使当前不显示在

iOS 自定义页面的切换动画与交互动画

在iOS7之前,开发者为了寻求自定义Navigation Controller的Push/Pop动画,只能受限于子类化一个UINavigationController,或是用自定义的动画去覆盖它.但是随着iOS7的到来,Apple针对开发者推出了新的工具,以更灵活地方式管理UIViewController切换. 自定义导航栏的Push/Pop动画 为了在基于UINavigationController下做自定义的动画切换,先建立一个简单的工程,这个工程的rootViewController是一个

iOS开发基础-图片切换(2)

延续:iOS开发基础-图片切换(1),对(1)里面的代码进行改善. 在 ViewController 类中添加新的数组属性:  @property (nonatomic, strong) NSArray *infoArray; //存放图片信息 通过 self.infoArray 的 getter 方法对其实现初始化(懒加载),其中代码中的 _infoArray 不能用 self.infoArray 替换: 1 //infoArray的get方法 2 - (NSArray *)infoArray

Android两个页面之间的切换效果工具类

import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Build; import android.widget.Toast; public class ActivityAnimationUtil { private Context context; pr

[iOS]终极横竖屏切换解决方案1

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 24.0px "Helvetica Neue"; background-color: #ffffff } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px "Helvetica Neue"; color: #8c8c8c; background-color: #ffffff } p.p3 { margin: 0.0px