2011-08-15 97 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并将应用程序委托连接到每个选项卡? –