0

我在故事板中的一個視圖控制器中添加了一個tableview作爲子視圖。它有6個部分,每個部分都有一排。在選擇每一行時,應該打開一個新的視圖控制器。有6個這樣的不同的視圖控制器。我不知道如何在故事板中實現這一點。有沒有什麼辦法通過故事板綁定這個,或者我必須手動完成。任何幫助都將被接受。 謝謝。Pushview on storyboard中的didselectrowatindexpath

回答

4

使用performSegueWithIdentifier方法,當你在視圖控制器故事板。

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


    if (indexPath.section==0) { 

     [self performSegueWithIdentifier:@"first" sender:nil]; 

    } 
    if (indexPath.section==1) { 

     [self performSegueWithIdentifier:@"second" sender:nil]; 

    } 
    if (indexPath.section==2) { 

     [self performSegueWithIdentifier:@"third" sender:nil]; 

    } 
    if (indexPath.section==3) 
    { 

     [self performSegueWithIdentifier:@"fourth" sender:nil]; 

    } 


} 

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if([[segue identifier] isEqualToString:@"first"]) 
    { 
     friendsViewController=[segue destinationViewController]; 

    } 
    if([[segue identifier] isEqualToString:@"second"]) 
    { 
     secondViewController=[segue destinationViewController]; 

    } 
    if([[segue identifier] isEqualToString:@"third"]) 
    { 
     thirdViewController=[segue destinationViewController]; 

    } 
    if([[segue identifier] isEqualToString:@"fourth"]) 
    { 
     fourthViewController=[segue destinationViewController]; 



    } 
} 

我認爲這會對您有所幫助。

1

如果你有靜態單元格的桌面視圖,並且它們都放置在故事板上,那麼你可以輕鬆地用ctrl按鈕拖動鼠標左鍵並從每個單元格向需要的ViewController創建segue。

+0

是的,我有靜態單元格,並已經嘗試了你說的方式,但我面臨的問題是,我採取了viewcontroller而不是一個tableviewcontroller。所以它顯示'靜態單元格只有在嵌入uitableviewcontroller內時纔有效'錯誤 – coder1010

相關問題