2016-04-13 16 views
1

テーブルビューで各セルを選択するときに別のビューを表示したいとします。TableViewで各セルを選択するときに別のビューを表示する

enter image description here

私は、この機能を使用する必要があることを考え出し:

func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) { 



} 

私はこの仕事をするために関数内で何を追加する必要がありますか?

+0

http://stackoverflow.com/questions/22759167/how-to-make-a-push-segue-when-a- uitableviewcell-is-selected look –

+0

'didSelectRowAtIndexPath'(' didDelectlect ... 'ではなく)の 'indexPath'でセルを検出し、上記のガイドに従います。 – Tj3n

答えて

0
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) 
{ 

    if indexPath.row == 0 
    { 
     let objOne = self.storyboard?.instantiateViewControllerWithIdentifier("ID_OneScene") as? OneScene 

     self.navigationController?.pushViewController(objOne!, animated: true) 

    } 
    else if indexPath.row == 1 
    { 
     let objTwo = self.storyboard?.instantiateViewControllerWithIdentifier("ID_TwoScene") as? TwoScene 

     self.navigationController?.pushViewController(objTwo!, animated: true) 

    } 
    else 
    { 
     let objOther = self.storyboard?.instantiateViewControllerWithIdentifier("ID_OtherScene") as? OtherScene 

     self.navigationController?.pushViewController(objOther!, animated: true) 

    } 

} 
1

まず第一に、あなたはdidSelectRowAtIndexPathを必要とし、関数内であなたが魔女セルをタップして知っているindexPath.rowを使用することができ、その後、あなたのnavigationControllerを確認して、あなたも

let viewControllerObj = self.storyboard?.instantiateViewControllerWithIdentifier("ViewControllerIdentifier") as? ViewController 
self.navigationController?.pushViewController(viewControllerObj!, animated: true) 

をするビューを作成してプッシュする必要があります...ゼロ

ではありませんが、それが役に立てば幸い

+0

indexPath.rowはセルのインデックスを表しますテーブル。通常、セルはViewModelで表される必要があります。それ以外の場合は、セルの内容を構築するときに、使用するviewModelの配列が必要です。 –

+0

はい、それは働いた。 (Y) – Mariah

関連する問題