標籤:
什麼是Segue
?Storyboard上每一根用來介面跳轉的線,都是一個UIStoryboardSegue對象(簡稱Segue)
Segue的屬性
?每一個Segue對象,都有3個屬性 唯一標識
@property (nonatomic,readonly)NSString*identifier;
來源控制器
@property (nonatomic,readonly)idsourceViewController;
目標控制器
@property (nonatomic,readonly)iddestinationViewController;
Segue的類型
?根據Segue的執行(跳轉)時刻,Segue可以分為2大類型 自動型:點擊某個控制項後(比如按鈕),自動執行Segue,自動完成介面跳轉 手動型:需要通過寫代碼手動執行Segue,才能完成介面跳轉
自動型Segue
?按住Control鍵,直接從控制項拖線到目標控制器
?點擊“登入”按鈕後,就會自動跳轉到右邊的控制器?如果點擊某個控制項後,不需要做任何判斷,一定要跳轉到下一個介面,建議使用“自動型Segue”
performSegueWithIdentifier:sender:
?利用performSegueWithIdentifier:方法可以執行某個Segue,完成介面跳轉?接下來研究performSegueWithIdentifier:sender:方法的完整執行過程
[self performSegueWithIdentifier:@“login2contacts”sender:nil];
// 這個self是來源控制器
1.根據identifier去storyboard中找到對應的線,建立UIStoryboardSegue對象 設定Segue對象的sourceViewController(來源控制器) 建立並且設定Segue對象的destinationViewController(目標控制器)
performSegueWithIdentifier:sender:
2.調用sourceViewController的下面方法,做一些跳轉前的準備工作並且傳入建立好的Segue對象
- (void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender;
// 這個sender是當初performSegueWithIdentifier:sender:中傳入的sender
3.調用Segue對象的- (void)perform;方法開始執行介面跳轉操作(1)如果segue的style是push 取得sourceViewController所在的UINavigationController 調用UINavigationController的push方法將destinationViewController壓入棧中,完成跳轉(2)如果segue的style是modal 調用sourceViewController的presentViewController方法將destinationViewController展示出來
Sender參數的傳遞
[self performSegueWithIdentifier:@“login2contacts”sender:@“jack”];
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender;
UITabBarController
?跟UINavigationController類似,UITabBarController也可以輕鬆地管理多個控制器,輕鬆完成控制器之間的切換,典型例子就是QQ、等應用
UITabBarController的簡單使用
?UITabBarController的使用步驟 初始化UITabBarController 設定UIWindow的rootViewController為UITabBarController 根據具體情況,通過addChildViewController方法添加對應個數的子控制器
?UITabBarController添加控制器的方式有2種 添加單個子控制器
- (void)addChildViewController:(UIViewController *)childController;
設定子控制器數組
@property(nonatomic,copy)NSArray*viewControllers;
?如果UITabBarController有N個子控制器,那麼UITabBar內部就會有N個UITabBarButton作為子控制項?如果UITabBarController有4個子控制器,那麼UITabBar的結構大致如所示
App主流UI架構結構
Modal
?除了push之外,還有另外一種控制器的切換方式,那就是Modal?任何控制器都能通過Modal的形式展示出來?Modal的預設效果:新控制器從螢幕的最底部往上鑽,直到蓋住之前的控制器為止?以Modal的形式展示控制器
- (void)presentViewController:(UIViewController*)viewControllerToPresent animated: (BOOL)flagcompletion:(void (^)(void))completion
?關閉當初Modal出來的控制器
- (void)dismissViewControllerAnimated:(BOOL)flagcompletion: (void (^)(void))completion;
13.ios之控制器管理2