2013-08-18 103 views
0

我使用故事板內的表視圖控制器。表視圖視圖控制器顯示下一視圖

我目前在故事板中有一個嵌入導航控制器的tableview控制器。此表視圖控制器鏈接到一個ObjectiveC文件。

通過代碼我可以使用tableView didSelectRowAtIndexPath方法顯示正確的數據的另一個表視圖控制器。

代碼:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    WorkoutType *workoutType = (WorkoutType *)[self.fetchedResultsController objectAtIndexPath:indexPath]; 
    WorkoutSetViewController *detailViewController = [[WorkoutSetViewController alloc] initWithWorkoutType:workoutType]; 

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

} 

但如果我嘗試在故事板第一TVC添加另一個表視圖控制器,它具有的ObjectiveC視圖控制器文件相關聯,並連接到它,這表視圖控制器沒有在顯示運行代碼。

我需要在視覺上,定製第二個表視圖,並試圖用賽格瑞推...如下:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([[segue identifier] isEqualToString:@"show"]) { 



     NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 

     WorkoutType *workoutType = (WorkoutType *)[self.fetchedResultsController objectAtIndexPath:indexPath]; 
     //WorkoutSetViewController *detailViewController = [[WorkoutSetViewController alloc] initWithWorkoutType:workoutType]; 
     WorkoutSetViewController *destViewController = segue.destinationViewController; 
     destViewController.workoutType = workoutType; 
     //[self.navigationController pushViewController:detailViewController animated:YES]; 


    } 
} 

但是當我運行這段代碼,第二個表視圖控制器甚至不雖然應用程序沒有崩潰,

無論我做錯了什麼都必須簡單,任何幫助將不勝感激。

謝謝

回答

0

的Alloc初始化新視圖控制器。使用此代碼來代替:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
WorkoutSetViewController *detailViewController = (WorkoutSetViewController *)[storyboard instantiateViewControllerWithIdentifier:@"coolID"]; 
[self.navigationController pushViewController:detailViewController animated:YES]; 

對於MainStoryboard寫你的故事板名稱和coolID寫一個你在故事板設置您的視圖控制器ID名稱。

2

簡單你必須瀏覽下面的代碼。 (當你在相同的故事板ViewController中工作時,無需設置故事板)

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(indexpath.row==0)//for first row click 
    { 
     WorkoutSetViewController *objWorkoutSetVC=[[WorkoutSetViewController alloc] i nitWithNibName:@"WorkoutSetViewController" bundle:nil]; 
     [self.navigationController pushViewController:objWorkoutSetVC animated:YES]; 
    } 
    else if(indexpath.row==1)//for second row click 
    { 
     //Put code in which screen you have to navigate 
    } 
} 
+0

我編輯了我的答案,現在檢查它。 –

相關問題