我正在研究一個有幾個ViewControllers的應用程序,並且有一個特定的ViewController「login ViewController」,我想從幾乎每個UIViewController都可以訪問它,我知道我可以通過使用segue從每個控制器到LoginViewController,我敢肯定這不是最好的解決方案,那麼實現這一目標的最佳解決方案是什麼?在Storyboard中以編程方式訪問UIViewController
1
A
回答
1
你也許可以做這樣的事情
static LoginViewController *instance; //place in the implementation
- (void) viewDidLoad {
instance = self;
}
+(LoginViewController *) getInstance { //use this method to access the instance (declare in header)
return instance;
}
則只需導入你需要訪問它的頭,你就大功告成
7
使用此...變量vc
返回你的視圖 - 控制尋找
UIStoryboard *aStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
YourViewController *vc = [aStoryboard instantiateViewControllerWithIdentifier:@"YourViewController"];
0
我建議你應該創建將由每個需要登錄v控制器被繼承基礎視圖控制器控制器。 然後在你基地的viewController,您可以創建這樣的方法:
-(YourLoginViewController*)giveMeTheLoginController {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"YourStoryboardName" bundle:nil];
YourLoginViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"YourLoginViewControllerIdentifier"];
return viewController;
}
如果你不想,你可以用同樣的方法在您的視圖控制器獲取視圖控制器的新實例基本視圖控制器從故事板。
另外使用每個視圖控制器的segues是一個好方法,segues用於定義您的導航。
1
實例化故事板的視圖控制器編程
列表2-2實例化相同的故事板
- (IBAction)presentSpecialViewController:(id)sender {
UIStoryboard *storyboard = self.storyboard;
SpecialViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"SpecialViewController"];
// Configure the new view controller here.
[self presentViewController:svc animated:YES completion:nil];
}
內的另一個視圖控制器
相關問題
- 1. 在UIViewController Storyboard中訪問UIView
- 2. 如何以編程方式繼承存儲在Storyboard中的UIViewController?
- 3. 在目標C中,如何以編程方式訪問UIViewController?
- 4. 以編程方式UIViewController Autorotation
- 5. 以編程方式更改storyBoard的rootViewController
- 6. 在iphone中訪問本地文件以編程方式編程
- 7. 以編程方式訪問UIViewController子類中的UIView子類的成員
- 8. 以編程方式創建uiviewcontroller
- 9. 以編程方式旋轉UIViewController
- 10. 如何以編程方式加載UIViewController?
- 11. 如何以編程方式創建UIViewController?
- 12. 如何以編程方式加載UIViewController
- 13. 以編程方式向UIViewController添加UITableView
- 14. 以編程方式旋轉UIViewController?
- 15. 是否有可能以編程方式從Swift/Objective-C中的UIViewController或Storyboard獲取基本UIViewController的標識符?
- 16. 以編程方式訪問iSight?
- 17. 以編程方式訪問Manifest.permission?
- 18. 以編程方式訪問Access Gateway
- 19. 以編程方式訪問Raphael路徑
- 20. 如何以編程方式訪問ItemPanel?
- 21. wp7以編程方式訪問SIM卡
- 22. 以編程方式訪問Infinispan MBeans
- 23. 以編程方式訪問TFS歷史
- 24. 以編程方式訪問ResourceDictionary項目
- 25. 以編程方式訪問字典鍵
- 26. 以編程方式訪問iTunes商店?
- 27. 以編程方式訪問WPF控件
- 28. 以編程方式訪問QFiledialog
- 29. 無法以編程方式訪問dijit.Dialog
- 30. 如何以編程方式訪問iptables?