前向引用
@class
多個MVC
一個MVC只能控制一個屏幕唐责,或者更小的區(qū)域,隨著程序變得越來越復(fù)雜脊凰,我們會需要多個MVC,那么如何在多個MVC之間進(jìn)行切換呢?
答案是使用:Controller of Controller : UINavigationController
UINavigationController
- 什么是UINavigationController
- UINavigationController也是繼承于UIViewController井联,不過它是用來控制控制器的控制器卜壕。
- UINavigationController有一個Outlet只向一另外一個MVC,就是它的rootViewController烙常。
- rootViewController就是出現(xiàn)在白色區(qū)域的, 原來的rootViewController放到UINavigationController后,它 的bounds高度會變小一些侦副。
-
UINavigationController通過執(zhí)行一個segues秦驯,可以跳轉(zhuǎn)到另外一個MVC上。就是把新的MVC push都屏幕上细燎,點返回,把當(dāng)前的MVC pop出來。
-
如何創(chuàng)建一個UINavigationController
Segues
- segues的三種方式:
- push
- modal:Puts the view controller up in a way that blocks the app until it is dismissed
- custom: You can create your own subclasses of
UIStoryboardSegue
IPAD ONLY:
- replace:Replaces the right-hand side of a UISplitViewController
- Popover - Puts the view controller on the screen in a popover
如何創(chuàng)建Segues:
ctrl + 拖拽一般是通過用戶切換來進(jìn)行跳轉(zhuǎn)但是有時候也可以通過 segueID在代碼里面進(jìn)行條件跳轉(zhuǎn)
- (void)performSegueWithIdentifier:(NSString *)segueId sender:(id)sender;
例子:
- (IBAction)rentEquipment
{
if (self.snowTraversingTalent == Skiing) {
[self performSegueWithIdentifier:@“AskAboutSkis” sender:self];
} else {
[self performSegueWithIdentifier:@“AskAboutSnowboard” sender:self];
}
}
- 跳轉(zhuǎn)之前準(zhǔn)備方法
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@“DoAParticularThing”]) {
UIViewController *newController = segue.destinationViewController;
}
// send messages to newController to prepare it to appear on screen
// the segue will do the work of putting the new controller on screen
}
- 通過名字從故事版實例化ViewController, 而不是從segue創(chuàng)建
- (IBAction)doit
{
DoitViewController *doit =
[self.storyboard instantiateViewControllerWithIdentifier:@”doit1”];
doit.infoDoitNeeds = self.info;
[self.navigationController pushViewController:doit animated:YES];
}