这与我之前问的一个问题有关,但最初的问题得到了回答。希望可以打开一个新问题,如果没有,请删除它。
我正在尝试使用TableView和Tabbar构建一个简单的iPhone应用程序。除了标题和需要显示的数据类型之外,每个视图在编程上都是相同的。除此之外,他们的行为都是一样的。
“我的AppDelegate”中的当前代码处理视图控制器到不同选项卡的分布,并相应地设置标题。但是,我无法理解的是,如何将特定的对象数组(每个数组的每个选项卡都不同)传递给每个分布式视图控制器,以便TableView使用它。
希望你能帮助我。我的代码如下:
AppDealth.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
AppDeavig.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
rootViewController实现UITableViewDataSource协议。