2011-05-31 39 views
0

我有一個基於視圖的項目與一組按鈕。添加tableView與導航控制器到基於視圖的項目 - iPhone編程

當其中一個按鈕被按下時,我想創建一個導航控制器的表視圖。我在另一個項目中有這個代碼。

我的代碼基本上是本教程有一些細微的變化(只是第2個部分): CODE

有沒有一種方法,這樣,當按下按鈕導入此代碼到我的主要項目前面的代碼執行?

編輯:

我用這個方法來讓我改變看法:

- (void) displayView:(int)intNewView{ 

NSLog(@"%i", intNewView); 
[currentView.view removeFromSuperview]; 
[currentView release]; 

switch (intNewView) { 
    case 1: 
     currentView = [[View1 alloc] init]; 
     break; 
    case 2: 
     currentView = [[View2 alloc] init]; 
     break; 
    case 3: 
     currentView = [[View3 alloc] init]; 
     break; 
    case 4: 
     currentView = [[View4 alloc] init]; 
     break; 
    case 5: 
     vc = [[RootViewController alloc] init]; 
     currentView = [[UINavigationController alloc] initWithRootViewController:vc]; 
     [self presentModalViewController: currentView animated:YES]; 
     break; 
} 

[UIView beginAnimations:nil context:nil]; 

[UIView setAnimationDuration:0.5]; 

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES]; 


[self.view addSubview:currentView.view]; 

[UIView commitAnimations]; 

} 

RootViewController的是正確的控制器。如果我刪除了2行:

currentView = [[UINavigationController alloc] initWithRootViewController:vc]; 
     [self presentModalViewController: currentView animated:YES]; 

而在rootview與currentView替代VC初始化器然後代碼工作,並顯示我的表,可以使用我的自定義細胞,併成功地解析XML並顯示正確的數據,但不一個導航控制器。但是,當我添加表視圖上方的2行不工作,我得到一個XML錯誤代碼5 ...任何想法?

感謝,

傑克

回答

1

您可以創建一個控制器(其中有你的表視圖),然後創建它的根控制器具有表視圖控制器導航控制器。從這裏你可以展示這個導航控制器。

導航控制器有一個稱爲

- (id)initWithRootViewController:(UIViewController *)rootViewController 

更新方法:

//創建根控制器。

RootController *controller = [[RootController alloc] initWithNibName:@"RootControllerNibName" bundle:nil]; 

//使用其根控制器創建您的導航控制器。

UInavigationController *navController = [UINavigationController initWithRootViewController:controller]; 

//呈現您的導航控制器。

[self presentModalViewController: navController animated:YES]; 

//發佈根控制器和導航控制器...

+0

嗨@pratikshabhisikar,我想我知道你來自哪裏,但我仍然得到錯誤...我已經編輯我的帖子包括這個,你能幫忙嗎?謝謝,傑克 – 2011-06-01 00:29:09

+0

你可以通過跳過''[present presentModalViewController:currentView animated:YES]來嘗試相同的代碼;'' ? – 2011-06-01 05:46:44

+0

是的,那有效,奇怪,我確定我昨天晚上累了,它沒有......沒有任何意識。無論如何感謝很多@pratikshabhisikar,問題解決了! – 2011-06-01 11:21:57

相關問題