2010-11-19 76 views
2

我有一個爲什麼self.navigationController pushViewController不工作?

UIViewController-> UINavigationBar的+的UITableView

只是有點更多的解釋

我通過UIBuilder做吧..

1:創建一個新的UIViewController with XIB-file
2:使用UIBuiler我把UINavigationController
3:後來我把UITableViewnavigationBar 所以它給了我下面..

答:UIViewController-> UINavigationBar的+的UITableView

現在我已經從正在工作的Web服務加載UITableView中的數據。

我再次由具有SAM配置一個XIB是

B:UIViewController-> UINavigationBar的+的UITableView

所以,現在,當我嘗試使用以下代碼對視圖A推視圖B中。 ..它慣於在所有的工作......

SelectSiteViewController *siteViewController = [[SelectSiteViewController alloc] initWithNibName:@"SelectSiteViewController" bundle:nil]; 

[self.navigationController pushViewController:siteViewController animated:YES]; 

當我檢查了UINavigationController *nav = self.navigation

nav是0x0,我假設爲NIL。

誰能告訴我什麼是錯在這裏..爲什麼是零...我怎樣才能使它工作..

非常感謝....我真的很感謝所有幫助

回答

3

在UIBuilder中,驗證UINavigationController是由文件所有者引用的。

+0

當你把從UIBuilder庫UINavigationBar的是一個UINavigationController?這是一個UINavigationBar。 – ujwaltrivedi 2010-11-19 14:23:46

+0

它只是在視圖中出現的酒吧。您需要在UIBuilder中拖放UINavigationController並將其掛接到文件所有者的導航控制器。或者你可以在代碼中創建。 – jamihash 2010-11-20 04:43:18

+0

嘿,我可以給你的代碼....我試過,但無法弄清楚......我真的很感激任何幫助...謝謝你 – ujwaltrivedi 2010-11-20 23:10:02

1

所以,你要添加tableview到導航控制器的權利?這是如何:

tableView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain]; 

navigationController = [[UINavigationController alloc] init]; 

[navigationController pushViewController:tableView animated:NO]; 

tableview作爲rootview添加到導航控制器。再上,如果你想推另一個視圖 - 控制選擇行使用

self.navigationController pushViewController: newViewController animated:YES]; 

的didSelectRowAtIndex方法內。

注意:它的UITableViewController * tableView和UINavigationController * navigationController是聲明的。所以相應地爲你的表編碼。

+0

否否... 我創建了一個新文件,它是帶有XIB選項Selected的UIViewController。用於離: @interface ClasssName:的UIViewController <一些代表> { } 所以它的UIViewController 的一個子類 現在我打開XIB文件拖放UINavigationBar的 然後我下降的UITableView到XIB文件是UIViewController中 這有幫助嗎? – ujwaltrivedi 2010-11-19 14:28:01

2

明白了。

我改變了建築的一點點。

我用它的xib創建了一個新的UIViewController類。並編寫新的UINavigationController。

- (void)viewDidLoad { 
[super viewDidLoad]; 
    UINavigationController *navigationController 
navigationController = [[UINavigationController alloc] init]; 
[self.view addSubview:navigationController.view]; 


switch (whichViewController) { 
    case 1: 
     viewController = [[xxxx alloc] init];   
     break; 
    case 2: 
     viewController = [[xxx1 alloc] init];   
     break; 
    default: 
     break; 
} 

[navigationController pushViewController:viewController animated:NO]; 
[viewController release]; 

}

,推動在switch語句中的視圖....

我希望這是有道理的......

感謝jamihash

0

爲什麼UIViewController-> UINavigationBar + UITableView?

我建議你另一種方法 - >的UITableViewController A - >與導航控制器的嵌入式,然後填充tableview中後,你可以將數據傳遞給 - 由 >的UITableViewController B [[自我情節提要] instantiateViewControllerWithIdentifier:@ 「ControllerB」] ;

然後,在故事板中,放置一個tableView B並在Identity-> storyboard Id中放置一些id。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
NSString *sUrl= @"<#string#>"; 
if (indexPath.row == 0) sUrl= @"http://www.apple.com/"; 
if (indexPath.row == 1) sUrl= @"http://www.google.com/"; 
if (indexPath.row == 2) sUrl= @"http://www.times.uk/"; 

NSMutableArray *selectedObject = [arrayOpenMale objectAtIndex:0]; 
NSLog(@"%@ is the selected object.",selectedObject); 

SeriesAdetailVC *dvc = [[self storyboard]instantiateViewControllerWithIdentifier:@"DetailView"]; 
dvc.strings7 = [NSURL URLWithString:sUrl]; 

[self.navigationController pushViewController:dvc animated:YES]; 

} 

希望幫助