2011-08-15 73 views
0

好的,我明顯是iOS開發新手,請耐心等待。我在Internet上看到的大多數教程都基於單個視圖模板,但我想將其中的一些組合到標籤欄中。我有三個屬性列表,我希望將它們分配給各個選項卡並用作向下鑽取導航數據。我被告知我可以將字典屬性分配給應用程序didFinishLaunching方法中的單個選項卡,但我不明白如何將它們分配給不同的選項卡。多視圖和應用程序委託?

因此,這裏是我有什麼

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

[self.window makeKeyAndVisible]; 
[self.window addSubview:rootViewController.view]; 

NSString *Path = [[NSBundle mainBundle] bundlePath]; 
NSString *DataPath = [Path stringByAppendingPathComponent:@"LocationsData.plist"]; 

NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath]; 
self.locationsData = tempDict; 
[tempDict release]; 

[self.window addSubview:locNavControl.view]; 
[window makeKeyandVisible]; 

NSString *Path = [[NSBundle mainBundle] bundlePath]; 
NSString *DataPath = [Path stringByAppendingPathComponent:@"IndustriesData.plist"]; 

NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath]; 
self.industryData = tempDict; 
[tempDict release]; 

[self.window addSubview:indNavControl.view]; 
[window makeKeyandVisible]; 

return YES; 
} 

的錯誤是在self.window addSubview:locNavControl.view因爲「請求的東西不是一個結構或聯合成員‘視圖’」。我想我可能會讓這個部分錯誤,因爲我希望當您按下一個選項卡時將它們推送到屏幕上。警告在makeKeyandVisible上,因爲「窗口」可能不響應。

我想我做錯了,但我不知道。一些幫助將不勝感激:)

回答

1

你只能在任何給定的時間一個視圖鍵!調用[window makeKeyandVisible] 3次不起作用。

編輯:

您的窗口只能有一個根視圖控制器。在你的情況下,它可能是一個標籤欄控制器。然後,您可以爲不同的選項卡創建單獨的控制器,並將它們添加到選項卡欄控制器。

編輯2

一般來說,你大概可以做這樣的事情......

在appdelegate.h文件

...

在實現文件
UITabBarController *tabBarController; 
UIViewController *vc1; 
UIViewController *vc2; 
//... etc 
UIViewController *vcn; 

然後, appdelegate.m,你應該初始化視圖控制器,然後將它們添加到你的tabbarcontroller。

//Your tabBarController should be connected to the user interface (XIB file), so no need to allocate it in code 

//here you can choose to allocate vc1 through vcn if they are not also set up in the XIB 
//I recommend doing setup like loading from plist files in each view controller's viewDidLoad method 

//If you didn't add the viewcontrollers in the XIB you could do something like this... 

NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2, ..., vcn, nil]; 
[tabBarController setViewControllers:viewControllers animated:NO]; 

self.window.rootViewController = tabBarController; 
[self.window makeKeyAndVisible]; 

這只是一個快速的指導方針,我希望澄清一些事情!我建議仔細查看文檔並瀏覽一些Apple的示例代碼和教程。他們非常有幫助!

+0

那我應該用什麼來代替它呢? –

+0

你應該重新檢查文檔。也許從XCode中的TabBarController模板開始,在線查找一個漂亮的tabbarcontroller教程。我無法真正告訴你應該將其替換,因爲我不確定你想要完成的是什麼。我添加了一個關於關鍵窗口的小筆記給我的答案.. – mjisrawi

+0

非常感謝。還有幾個問題 - 你將如何去完成這個任務,併爲應用程序didFinishLaunching方法中的每個單獨的選項卡分配屬性,以及如何獲取代碼連接?我只需進入我的mainwindow.xib並將應用程序委託連接到每個選項卡? –