我想在swift項目中使用「AHTabBarController」。AHTabBarController與Swift不兼容
我不知道爲什麼這個代碼不工作:
var tabBarController = self.window?.rootViewController as AHTabBarController
var tab1 = AHTabView()
tab1.image = UIImage(named: "")
tab1.title = "Tab 1"
var tab1_subItem = AHSubitemView(frame: UIScreen.mainScreen().bounds)
tab1_subItem.image = UIImage(named: "")
tab1_subItem.title = "Tab 1 Title"
tab1_subItem.viewControllerIdentifier = "channelsListSB"
tab1.addSubitem(tab1_subItem)
tabBarController.tabs.addObjectsFromArray([tab1])
self.window?.rootViewController = tabBarController
Objective-C的代碼是:
AHTabBarController *tabBarController = (AHTabBarController*)self.window.rootViewController;
/******* PURUS *******/
AHTabView *purus = [AHTabView new];
[purus setImage:[UIImage imageNamed:@"persondot"]];
[purus setTitle:@"Purus"];
AHSubitemView *pFirst = [AHSubitemView new];
[pFirst setImage:[UIImage imageNamed:@"persondot"]];
[pFirst setTitle:@"First"];
[pFirst setViewControllerIdentifier:@"PurusFirst"];
[purus addSubitem:pFirst];
// …
AHSubitemView *fFirst = [AHSubitemView new];
[fFirst setImage:[UIImage imageNamed:@"photos"]];
[fFirst setTitle:@"First"];
[fFirst setViewControllerIdentifier:@"FringillaFirst"];
[fringilla addSubitem:fFirst];
//Don't forget to add your AHTabView instances to the AHTabBarController!
[tabBarController.tabs addObjectsFromArray:@[purus, fringilla, ipsum]];
的錯誤是:
fatal error: unexpectedly found nil while unwrapping an Optional value
*我不知道爲什麼這段代碼不工作*是一個完全無用的描述。什麼不能像例外一樣工作?你能指望什麼? – idmean 2015-03-02 16:37:13
致命錯誤:在解包可選值時意外發現爲零 – Ahmad 2015-03-02 18:23:53
您是否知道打開可選值的含義?哪一行導致此問題? – 2015-03-02 18:29:11