2012-01-03 33 views
1

我有一個問題推動我的視圖控制器從一個tableview被放入viewController,而不是一個TableViewController。從viewview裏面的viewController不工作推動viewController

我發現一個線程在這裏的這裏

pushViewController is not pushing

解決的問題是..我做了他的解決辦法,我的看法仍然沒有推。我已經連接我的桌​​面視圖通過CTRL +拖動到視圖控制器並設置數據源和委託。在我提到的文章中,他們說解決方案是'從tableview創建一個引用插座到視圖控制器。'但我不完全知道這意味着什麼。所以,這樣做的幫助也會很好。我跟着this tutorial,明顯地卡在第9步。

的代碼不會觸發線是

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

我的代碼如下...

viewTable方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
NSLog(@"list Size: %@",list); 
    return [list count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if(cell == nil){ 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
} 
CustomerListData *customer = [self.list objectAtIndex:indexPath.row]; 
cell.textLabel.text = customer.facilityName; 

// cell.textLabel.text = @"Detail"; 
return cell; 
} 

-(void)setValue:(NSMutableArray*)array 
{ 
//NSMutableArray *newArray = [[NSMutableArray alloc] init]; 
list = array; 
} 

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

FacilityMissionListViewController *facility = [self.storyboard instantiateViewControllerWithIdentifier:@"facilityMissionList"]; 
[self.navigationController pushViewController:facility animated:YES]; 
//UINavigationController* navController = self.navigationController; 
} 

的最後註釋掉行是有檢查navigationcontroller爲null。不是這樣。

從我所收集的問題來看,這裏的問題在於表視圖在視圖控制器內部,而不是「tableviewcontroller」。如果是這種情況,這種方法顯然是有效的,但是如果不是這樣的話,必須採取其他一些步驟,但我不知道它們。

在此先感謝。

回答

0

這聽起來像您的NavigationController沒有正確設置。你能發佈設置它的代碼嗎?

+0

我的錯誤..導航控制器從來沒有建立(自從我參與這個項目以來,它已經有一段時間了)。我一直在使用segues而不是導航控制器來處理所有的視圖轉換。我切換到segue設置,它工作得很好。我想現在我的問題是......這會影響表和數據傳遞等任何東西嗎?使用segues或導航控制器有什麼區別? – 2012-01-03 19:19:49

+0

從我所瞭解的情況來看,您仍然必須像以前一樣設置數據並將其傳遞到新的ViewController(設施)。 – 2012-01-03 19:25:54

+0

謝謝安德魯。只要功能上基本一樣,一切都很好。 – 2012-01-03 19:26:04

0

放一個:

NSLog(@"%@", self.navigationController); 

在您的didSelectRowAtIndexPath方法方法,你會看到,如果該方法被調用,如果navigationController是零。這可能是這種情況之一。

否則請確保FacilityMissionListViewController不爲零。

+0

好的,點擊按鈕確實會調用該方法,但self.navigationcontroller實際上是null。顯然,另一種檢查方式是不準確的。那麼我在這裏做什麼? – 2012-01-03 19:10:58

相關問題