テーブルビューで各セルを選択するときに別のビューを表示したいとします。TableViewで各セルを選択するときに別のビューを表示する
私は、この機能を使用する必要があることを考え出し:
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
}
私はこの仕事をするために関数内で何を追加する必要がありますか?
テーブルビューで各セルを選択するときに別のビューを表示したいとします。TableViewで各セルを選択するときに別のビューを表示する
私は、この機能を使用する必要があることを考え出し:
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
}
私はこの仕事をするために関数内で何を追加する必要がありますか?
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)
}
}
まず第一に、あなたはdidSelectRowAtIndexPath
を必要とし、関数内であなたが魔女セルをタップして知っているindexPath.row
を使用することができ、その後、あなたのnavigationController
を確認して、あなたも
let viewControllerObj = self.storyboard?.instantiateViewControllerWithIdentifier("ViewControllerIdentifier") as? ViewController
self.navigationController?.pushViewController(viewControllerObj!, animated: true)
をするビューを作成してプッシュする必要があります...ゼロ
ではありませんが、それが役に立てば幸い
indexPath.rowはセルのインデックスを表しますテーブル。通常、セルはViewModelで表される必要があります。それ以外の場合は、セルの内容を構築するときに、使用するviewModelの配列が必要です。 –
はい、それは働いた。 (Y) – Mariah
http://stackoverflow.com/questions/22759167/how-to-make-a-push-segue-when-a- uitableviewcell-is-selected look –
'didSelectRowAtIndexPath'(' didDelectlect ... 'ではなく)の 'indexPath'でセルを検出し、上記のガイドに従います。 – Tj3n