ナビゲーションコントローラを持つVC内にテーブルビューがあり、カスタムテーブルセルが含まれています。カスタムテーブルセルのボタンがタップされている場合、親VCのナビゲーションスタックにプッシュするのがベストプラクティスであると思っていました。親VCのナビゲーションコントローラをセルに渡すと、これを動作させることができます。これは最も効果的な/効率的な練習ですか?iOS Swift:カスタムTableviewセル内からビューをスタックにプッシュする
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
}
}
事前にありがとうございます!
ありがとう、これは知っておいてよかったです! –