これは私が以前に尋ねた質問に関連していますが、元の質問に答えました。新しい質問を開いても問題ないことを願っています。そうでない場合は、遠慮なく削除してください。
テーブルビューとタブバーを使用して、簡単なiPhoneアプリケーションを作成しようとしています。タイトルと表示する必要のあるデータの種類を除いて、すべてのビューはプログラムで同じです。それを除いて、それらはすべて同じように動作します。
現在、私のAppDelegateのコードは、ビューコントローラのさまざまなタブへの配布を処理し、それに応じてタイトルを設定します。ただし、私が理解できないのは、オブジェクトの特定の配列(すべての配列はタブごとに異なります)を各分散ビューコントローラーに渡して、テーブルビューで使用されるようにする方法です。
あなたが私を助けてくれることを願っています。私のコードは以下の通りです:
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
RootViewControllerは、UITableViewDataSourceプロトコルを実装します。