2011-10-09 7 views
1

私は今数週間探しており、タブバーアプリケーションにテーブルビューを追加する方法を示すXcode 4のチュートリアルを探してみることはできませんでした。あなたが正しい方向に私を向けることができるかどうか疑問に思っていましたか?あなたはタブバーにUIViewControllersを追加するための任意のTabBarControllerチュートリアルが何をすべきTab Bar Appのテーブルビュー

おかげ

+0

自分のinitにそれらにタブバーの項目を追加します:のhttp: //www.youtube.com/watch?v=LBnPfAtswgw –

答えて

2

。テーブルビューの場合、単純にUITableViewControllerを作成します。これをタブバーコントローラ...または他のビューコントローラに追加することができます。たとえば、navigationControllerを使用してTabBarを実行する他のチュートリアルがある場合は、チュートリアルのnavigationController部分を単にUITableViewControllerに置き換えます。また、UItableViewControllerにはたくさんのドキュメントやチュートリアルがあります。

たとえば、このコードをアプリケーションデリゲートのdidfinishLaunchingWithOptionsで確認すると、これに対して、MyTableViewController(UITableViewController)と他のUIViewControllerが作成されました。

// View Controllers for tabController - could be UItableViewControllers or any 
// other UIViewController. You will add this to the tabController 
NSMutableArray *viewControllers = [[NSMutableArray alloc] init]; 

MyTableViewController *myTable = [[MyTableViewController alloc] initWithNibName:@"MyTableViewController" bundle:nil]; 
[viewControllers addObject:myTable]; 

SomeOtherUIViewController *other = [[SomeOtherUIViewController alloc] initWithNibName:@"SomeOtherUIViewController" bundle:nil]; 
[viewControllers addObject:other];  

// add the UIViewControllers to the tabController 
[tabController setViewControllers:viewControllers]; 

// add tabbar and show 
[[self window] addSubview:[tabController view]]; 
[self.window makeKeyAndVisible]; 
return YES; 

そしてあなたはタブバーに追加し、それらのビューコントローラのそれぞれには、必ずそれがxcode4ではないのですが、それは便利です

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) 
    { 
     UITabBarItem *barItem = [[UITabBarItem alloc] 
          initWithTitle:@"Progress" 
          image:[UIImage imageNamed:@"report.png"] tag:2]; 

     [self setTabBarItem:barItem]; 
     [barItem release]; 
    } 
    return self; 
} 
関連する問題