あなたが直接それをやってするのではなくUITabBarを表示するためにUITabBarControllerを使用する必要があります。
次に、特定のタブのビューコントローラとしてUITableViewControllerを使用します。行が選択されたときに子孫UITableViewsを表示したいという印象を受けますが、このような場合は、UINavigationControllerをタブバーのView Controllerとして使用し、UITableViewControllerを管理させる必要があります。
iOSでは、実際にはビューコントローラパターンを使用する必要があることを覚えておいてください。フレームワークは、あなたのために多くのことを気にしています。
フォローアップ:
OK、以下の簡単な実装では、私のためにうまく動作します。このコードの多くの明白な問題は無視してください(私はアプリケーションデリゲートですべてを一緒にハックしました!純粋にあなたのコントローラーを一緒に接着する方法のモデルとして意図されています。
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITableViewDelegate, UITableViewDataSource>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navController;
@end
@implementation AppDelegate
@synthesize window = _window;
@synthesize navController = _navController;
- (void)dealloc
{
[_navController release];
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UITableViewController *rootTVC = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
[[rootTVC tableView] setDelegate:self];
[[rootTVC tableView] setDataSource:self];
[rootTVC setTitle:@"Root Table"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootTVC];
[rootTVC release];
[navController setTitle:@"My Table"];
UIViewController *anotherViewController = [[UIViewController alloc] init];
[anotherViewController setTitle:@"Not the table"];
UITabBarController *tbc = [[UITabBarController alloc] init];
[tbc setViewControllers:[NSArray arrayWithObjects:navController, anotherViewController, nil]];
[self setNavController:navController];
[navController release];
[anotherViewController release];
[[self window] setRootViewController:tbc];
[tbc release];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *reuseIdentifier = @"foo";
UITableViewCell *cell = [[tableView dequeueReusableCellWithIdentifier:reuseIdentifier] retain];
if (! cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
}
[[cell textLabel] setText:[NSString stringWithFormat:@"Row %d", [indexPath row]]];
return [cell autorelease];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewController *newTVC = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
[newTVC setTitle:[NSString stringWithFormat:@"Table %d", [indexPath row]]];
[[newTVC tableView] setDelegate:self];
[[newTVC tableView] setDataSource:self];
[[self navController] pushViewController:newTVC animated:YES];
}
@end
私はUITabBarControllerを使用しています。これをより明確に指定しないと申し訳ありません。 –
その後、 'didSelectRowAtIndexPath:'で何をしているのかを詳しく調べることができますか。 –
あなたがしていることは正しいようです。実際に何が起こっているのかを把握するために、これをプロジェクトに設定する必要があります。 –