![](/img/trans.png)
[英]MONOTOUCH open a viewcontroller on tableview cell is clicked
[英]Open specific viewController in tableView
我正在使用tableView
像iPhone的note應用程序。 我可以添加/刪除便箋( cells
)。
刪除記事時,我遇到了一個小問題。
這是我的代碼:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true)
switch (indexPath as NSIndexPath).row {
case 0:
let Liste1 = self.storyboard!.instantiateViewController(withIdentifier: "liste1") as UIViewController
self.present(Liste1, animated: false, completion: nil)
case 1:
let Liste2 = self.storyboard!.instantiateViewController(withIdentifier: "liste2") as UIViewController
self.present(Liste2, animated: false, completion: nil)
case 2:
let Liste3 = self.storyboard!.instantiateViewController(withIdentifier: "liste3") as UIViewController
self.present(Liste3, animated: false, completion: nil)
default:
break
}
如您所見,每個indexPath.row
都可以打開一個計數的ViewController
。 如果我有3個音符並刪除了第二個音符,則第三個viewController
將打開第二個viewController
。 告訴我您是否不了解。我知道問題,我不知道是否有一些解決方案可以打開特定的viewController
。
我希望Cells鏈接到viewController
,而不是通過indexPath鏈接。
提前致謝 !
這里的實現是錯誤的。 應該是,只要用戶選擇一個單元格,就應該推一個ViewController(例如名為DetailsViewController)。 僅與文本相關的文本/注釋應更改。 應該從所有便箋的數組中獲取正確的便箋(索引為所選單元格的indexPath.row),然后在呈現時將其傳遞給DetailsViewController。
刪除便箋:用戶刪除便箋時,只需從此所有便箋數組中刪除not即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.