クラス関数を介して別のクラスからsegueを実行しようとしています。ストーリーボードを使用せずに別のクラスからSegueを実行する
私はMyTableViewController
というクラスを持っています。そのクラスでは、私はタイプコントローラAnswerViewController
を構築しました。このビューコントローラへのセグは、Extension : MyCell
の条件が満たされたときに発生すると考えられます。私が抱えている問題は、関数showNextView
が呼び出されていないということです。
私はPerform Segue From Another Swift File via a class functionとPerform Segue from another class with helper functionの両方に記事を読んでいるが、これらの両方が(私はストーリーボードを使用していないので、できないことと、実際にseguesを持っていない、だけpushViewController
)ビューコントローラを構築する前セグエを作成します。
class MyTableViewController: UITableViewController {
//Construct View Controller
let answerViewController = AnswerViewController()
//Create goToNextView function which will be called in extension MyCell
func goToNextView(){
navigationController?.pushViewController(answerViewController, animated: true)
}
}
extension MyCell: YSSegmentedControlDelegate{
func segmentedControl(_ segmentedControl: YSSegmentedControl, willPressItemAt index: Int) {
tagToIndex[actionButton.tag] = index
print(tagToIndex)
//Condition To Be Met
if tagToIndex == [0:1,1:0,2:1]{
//Access function goToNextView from MyTableViewController
func showNextView(fromViewController : MyTableViewController){
fromViewController.goToNextView()
}
}
}
}
セグが発生するようにshowNextView
関数を呼び出すにはどうすればよいですか?
おかげで、 ニック