Multiple Views and an Application Delegate?
Alright, I'm obviously new to iOS development, so bear with me. Most tutorials that I see floating around the Internet are based on the single view template, but I would like to combine some of them into a tab bar. I have three property lists that I would like to assign to individual tabs and use as drill-down navigation data. I've been told that I can assign dictionary properties to individual tabs from the application didFinishLaunching method, but I do not understand how I can assign them to different tabs.
So here's what I have
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
[self.window addSubview:rootViewControl开发者_运维技巧ler.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;
}
The error is on self.window addSubview:locNavControl.view because "request for member 'view' in something not a structure or union". I think I might have that part wrong, because I want it to push that data onto the screen when you press a tab. Warning is on makeKeyandVisible because "window" may not respond.
I think I'm doing it wrong, but I would have no idea. Some help would be greatly appreciated :)
You can only make one view key at any given time! Calling [window makeKeyandVisible] 3 times doesn't work.
Edit:
Your window can only have one root view controller. In your case it would probably be a tab bar controller. Then you can create individual controllers for the different tabs and add them to the tab bar controller.
Edit 2
In general you could probably do something like this...
in your appdelegate.h file...
UITabBarController *tabBarController;
UIViewController *vc1;
UIViewController *vc2;
//... etc
UIViewController *vcn;
Then in your implementation file, appdelegate.m, you should initialize the view controllers, then add them to your 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];
This is just a quick guideline which I hope cleared up a few things! I recommend looking closely at the documentation and going through some of Apple's sample code and tutorials. they're very helpful!
It seems to me that you could benefit from using a UITabBarController to achieve the tab-based navigation you mention. Read Apple's UITabBarController documentation for more information.
精彩评论