2015-02-10 64 views
2

我有一个填充了多个动态单元格的TableView。我有代码来执行segue,一旦单元被轻敲,但是我需要使它成为每个单元执行不同的segue。有人可以帮助我,因为我使用的代码只是继续执行第一次segue,无论我按哪个单元格!为每个TableView单元格执行不同的Segue

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    NSLog("You selected cell number: \(indexPath.row)!") 
    if indexPath.row == 0 
    { 
     self.performSegueWithIdentifier("MoveToSignIn", sender: self) 
    } 
    if indexPath.row == 1 
    { 
     self.performSegueWithIdentifier("MoveTo2", sender: self) 
    } 
} 
+1

你有表格视图中的部分吗? – Miknash 2015-02-10 14:07:03

+0

我没有章节号,只有6动态单元格... – Alex 2015-02-10 14:12:56

回答

0

这里发生了什么(我非常确定这是问题)是部分。一个表不可能有两个单元格具有相同的区段和行值。解决方法应该是这样的:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    NSLog("You selected cell number: \(indexPath.row)!") 
    if indexPath.row == 0 && indexPath.section == 0 
    { 
     self.performSegueWithIdentifier("MoveToSignIn", sender: self) 
    } 
    if indexPath.row == 0 && indexPath.section == 1 
    { 
     self.performSegueWithIdentifier("MoveTo2", sender: self) 
    } 
} 

节仅复位你行,所以很容易混淆,因为你有5行,但两节或某事非常相似。

+0

感谢您的评论,我试过这个,它仍然做和以前完全一样的东西?我明白我以前出错了,我认为这会工作,但仍然没有:( – Alex 2015-02-10 14:13:31

+0

你的NSLog说什么? – Miknash 2015-02-10 14:14:43

+0

它告诉我我选择了哪一个单元格,并且根据我点击哪个单元格而改变 ' 2015-02-10 22:12:05.268 Alex [66789:2789442]你选择了单元格数目:2!' – Alex 2015-02-10 14:19:33

相关问题