2014-03-19 40 views
0

我已經查看了表格,表格中填入了動態數據。我需要根據特定的行切換到不同的視圖。 我需要檢查用戶是否在單詞「BMW」上單擊一行,然後您需要打開「機器」視圖,並且如果帶有單詞「suzuki」的行打開摩托車視圖。 我用這個故事板。如何從動態單元格切換到3個或更多不同視圖

+0

隨着故事板我現在不是如何做到這一點。我試着用xib文件。 ImageViewController * obj = [[ImageViewController alloc] initWithNibName:@「ImageViewController」bundle:nil]; [self.navigationController pushViewController:obj animated:YES];但它不起作用 – DimonDeveloper

+0

有關此主題的SO有很多問題。使用'tableView:didSelectRowAtIndexPath'和'performSegueWithIdentifier:sender:'。 –

回答

1

剛纔的所有控制器從SEGUE連接到該控制器。請注意,不要將segue連接到任何按鈕的otlet,而應將其與整個viewcontroller連接。然後按照以下步驟:

​​
+0

非常感謝。是工作。 – DimonDeveloper

1

您可以UITableView

使用didSelectRowAtIndexPath例如:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    NSString * name = [namesArray objectAtIndex:indexPath.row]; 

    if ([name isEqualToString:@"BMW"]) 
    { 
     //Open Machine View 

     MachineInfoController * info = [[MachineInfoController alloc] init]; 

     // If you use `UINavigationController` use this line 
     [self.navigationController pushViewController:info animated:YES]; 

     // If you are not using `UINavigationController` use this line 
     [self presentViewController:info animated:YES completion:nil]; 

     info = nil; 
    } 
    else if ([name isEqualToString:@"suzuki"]) 
    { 
     //Open Motorcycle View 

     MotorCycleInfoController * info = [[MotorCycleInfoController alloc] init]; 

     // If you use `UINavigationController` use this line 
     [self.navigationController pushViewController:info animated:YES]; 

     // If you are not using `UINavigationController` use this line 
     [self presentViewController:info animated:YES completion:nil]; 

     info = nil; 
    } 
} 
+0

但在這一行寫什麼/ /打開機器視圖 – DimonDeveloper

+0

請參閱上面,我已經更新了我的答案。 – Natarajan

+0

我使用你的代碼,我有例外,' - [UIViewController _loadViewFromNibNamed:bundle:]加載了「ImageView」筆尖,但沒有設置視圖插口。 – DimonDeveloper

相關問題