2016-09-27 50 views
0

我想鏈接兩個視圖控制器內我的應用程序,但我不知道如何將它們連接它們沒有附加到我的tableview單元格。我希望它只是一個帶有標識符的簡單segue,所以我可以用標識符調用perfrom segue。但是,我只能通過將它從我的單元格拖到下一個視圖控制器來創建一個segue。Swift之間的VC之間沒有什麼可鏈接

下面是我試圖鏈接的兩個VC的圖像,顯​​示了被選中的單元格。

http://imgur.com/gallery/PWJol

我無法弄清楚如何做到這一點。

這是我使用的代碼,這似乎是正確的。我希望它在選中一行時傳遞並傳遞所選行的標籤名稱。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    self.NameToPass = DietSelectionTableViewCell.TypesOfDiets[indexPath.row] 
    self.performSegue(withIdentifier: "DietInformation", sender: self) 
} 


// MARK: - Navigation 

// In a storyboard-based application, you will often want to do a little preparation before navigation 
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "DietInformation" { 
     if let destinationVC = segue.destination as? DietInformationViewController { 
      destinationVC.DietTypeLabelText = self.NameToPass 
     } 
    } 
    // Get the new view controller using segue.destinationViewController. 
    // Pass the selected object to the new view controller. 
} 
+2

在您從segueing現場,按住Ctrl鍵單擊頂部的橙色圓圈(代表視圖控制器本身)和阻力到您繼續使用的視圖控制器。 – pbasdf

回答

2

控制拖動從視圖控制器本身。它由場景上方矩形中的第一個圓圈表示。

在此圖像中,我已經強調了,你應該控制拖動的東西:

enter image description here

或者,你可以在使用左側的列表中。只需控制 - 從視圖控制器拖動。再次,我已經強調了,你應該控制拖動的東西:

enter image description here

相關問題