This is related to a question I asked earlier, but the original question was answered. Hope it's okay to open a new question, if not, feel free to delete it.
I'm trying to build a simple iPhone application using tableviews and a tabbar. Every view is the same programmatically, except for the title and the kind of data which needs to be displayed. Except for that they all behave the same.
Currently code in my AppDelegate handles the distribution of viewcontrollers to the different tabs and sets the title accordingly. What I can't figure out however, is how to pass a specific array of objects (every array differs per tab) to each distributed viewcontroller so that it's used by the tableview.
Hope you can help me out. My code follows below:
AppDelegate.h
#import <UIKit/UIKit.h>
@interface MyAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
AppDelegate.m
#import "RootViewController.h"
#import "MyAppDelegate.h"
@implementation MyAppDelegate.h
@synthesize window, tabBarController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSDictionary *row1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"1", @"Id",
@"My Name", @"Name",
@"My Type", @"Type",
@"My Meta", @"Meta",
@"My Excerpt Text", @"Excerpt",
@"My Body Text", @"Body",
@"icon.jpg", @"Icon",
@"image.jpg", @"Image", nil];
NSArray *array = [[NSArray alloc] initWithObjects:row1, nil];
self.events = array;
NSArray *tableControllersConfig = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:@"test1", @"DataSource", @"Title of the Tableview", @"Title", @"icon.png", @"Icon", nil],
NSMutableArray *tableControllers = [NSMutableArray array];
for (NSDictionary *configDict in tableControllersConfig) {
RootViewController *controller = [[RootViewController alloc] initWithNibName:@"TableView" bundle:nil];
controller.tableView.delegate = controller;
controller.title = [configDict valueForKey:@"Title"];
controller.tabBarItem.image = [UIImage imageNamed: [configDict valueForKey:@"Icon"]];
[tableControllers addObject:controller];
[controller release];
}
self.tabBarController.viewControllers = [NSArray arrayWithArray:tableControllers];
[window addSubview:tabBarController.view];
[row1 release];
[array release];
}
- (void)dealloc {
[tabBarController release];
[window release];
[super dealloc];
}
@end
The RootViewController implements the UITableViewDataSource protocol.