2012-04-05 2 views
0

UITabBarとUITableViewsを設定してGUIを取得しようとしています。UITabBarsとUITableViews。表のセルがクリックされたときにタブバーを画面に表示する

プログラムで作成されたUITabViewがあります。 タブの1つにプログラムで作成されたUITableViewが表示されます。

このUITableViewは、didSelectRowAtIndexPathが呼び出されたときに、他のビューを表示します。

テーブルセルをクリックすると、タブビューが消えて新しいテーブルビューが表示されます。

私が頭を上げることができないのは、tabBarが画面上にとどまるようにビューを構造化する方法です。

UITableViewsを短くするのと同じくらいシンプルなのですか、それともいくつかのウィンドウ/ビューmojoがありますか?

おかげ

答えて

4

あなたが直接それをやってするのではなく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 
+0

私はUITabBarControllerを使用しています。これをより明確に指定しないと申し訳ありません。 –

+0

その後、 'didSelectRowAtIndexPath:'で何をしているのかを詳しく調べることができますか。 –

+0

あなたがしていることは正しいようです。実際に何が起こっているのかを把握するために、これをプロジェクトに設定する必要があります。 –

0

UITabBarの代わりにUITabBarControllerを使用してください。

+0

私は午前。これを指定しないと申し訳ありません。 –

関連する問題