我在具有導航控制器並且包含自定義表格單元格的VC中有一個tableview。我想知道如果點擊自定義表格單元格中的按鈕,推入父VC的導航堆棧的最佳做法是什麼。如果我將父VC的導航控制器傳遞給單元格,我可以得到這個工作;但這是最有效/最有效的做法嗎?請參閱我目前的執行如下:iOS Swift:從自定義表格視圖中將視圖推送到堆棧單元格
UserAccountVC:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:TextPostTableViewCell = Bundle.main.loadNibNamed("TextPostTableViewCell", owner: self, options: nil)?.first as! TextPostTableViewCell
cell.setupCell(navigationController: self.navigationController!)
cell.selectionStyle = .none
return cell
}
CustomTableCell:
import UIKit
class TextPostTableViewCell: UITableViewCell {
var aNavigationController: UINavigationController!
//MARK: Actions
@IBAction func profilePicButtonTapped() { //We want to present a users profile
let sb = UIStoryboard(name: "SuccessfulLogin", bundle: nil)
let cc = (sb.instantiateViewController(withIdentifier: "otherUserViewController")) as! OtherUserAccountViewController
self.aNavigationController.pushViewController(cc, animated: true)
}
func setupCell(navigationController: UINavigationController) -> Void {
aNavigationController = navigationController
}
}
預先感謝您!
非常感謝,這是很好的知道! –