IOS-如何在UITableViewCell裏進入ViewController

衆所周知,我們在導航控制器中想進入一個controller 很簡單

[self.navigationController pushViewController:(自己的VC) animated:(BOOL值 YES 或者NO)];

但是有時候我們也會在TableviewCell中 進入一個ViewController 那要如何做呢?


我們可以根據Model進行跳轉VC Model 做一箇中轉


h文件聲明:


@interface MYUtilities : NSObject


- (void) enterViewController:(UIViewController *)viewController;


m文件實現

- (void) enterViewController:(UIViewController *)viewController

{

    UINavigationController *navControl = (UINavigationController*)([UIApplication sharedApplication].keyWindow.rootViewController); 

    [navControl pushViewController:viewController animated:YES];

}


剩下的我們只需要在自定義的Cell中要跳轉VC的地方 創建實例 執行方法 

MYUtilities *utilities = [[MYUtilities alloc] init];

                [utilities enterViewController:(你想去的VC)];


這樣一來雖然方便了,但是不推薦這樣使用,我們可以使用代理 調到VC中實現 頁面跳轉


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章