您手動必須通過發送方標籤
func bar(sender: UIButton!) {
if sender.tag == 0 {
self.performSegueWithIdentifier("viewcontroller1", sender: tableView)
}
else if sender.tag == 1 {
self.performSegueWithIdentifier("viewController2", sender: tableView)
}
//...... and so on
}
並實行以下方法
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "viewController1" {
let indexPath:NSIndexPath = self.tableView.indexPathForSelectedRow()!
let detailVC = segue.destinationViewController as ViewController1
detailVC.item = items[indexPath.row] as Item // Pass your data
}
else if segue.identifier == "viewController2" {
}
//...... and so on
}
或者,如果你想手動導航按鈕從事件則
func bar(sender: UIButton!) {
if sender.tag == 0 {
let indexPath:NSIndexPath = self.tableView.indexPathForSelectedRow()!
let detailVC = self.storyboard?.instantiateViewControllerWithIdentifier("view1SegueIdentifier") as! ViewController1 // view1SegueIdentifier -> assign it from storyboard
detailVC.item = items[indexPath.row] as Item // Pass your data
self.navigationController!.pushViewController(detailVC, animated:true)
}
else if sender.tag == 1 {
}
//...... and so on
}
做u想要什麼? – iAnurag
如[此](http://stackoverflow.com/questions/28695969/how-to-call-show-another-view-controller-when-clicked-on-the-cell-of-table-vie) –
ù想要按照不同的視圖控制器按照不同的視圖控制器獲取clickedl? – iAnurag