我已经从下到上阅读了this thread(以及类似的其他),但它根本不符合我的需求。Swift /如何使用popViewController调用委托
我有一个UIViewController
里面UIPageViewController
在UINavigationController
内。导航到第二个ViewController。导航到第三个ViewController并想回到第二个ViewController传递数据。
我当前的代码:
protocol PassClubDelegate {
func passClub(passedClub: Club)
}
class My3rdVC: UIViewController {
var clubs: [Club] = []
var passClubDelegate: PassClubDelegate?
....
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let club = clubs[indexPath.row]
self.passClubDelegate?.passClub(club)
navigationController?.popViewControllerAnimated(true)
}
我的第二个VC:
class My2ndVC: UIViewController, PassClubDelegate {
var club = Club()
func passClub(passedClub: Club) {
SpeedLog.print("passClub called \(passedClub)")
club = passedClub
}
passClub
不叫。我确定这是因为我没有将代理设置为My2ndVC,但我该怎么做?我找到的所有解决方案都希望我使用a)segue或b)实例化一个My2ndVC new,它没有任何意义,因为它仍然在内存中,我想弹回来重新回到层次结构中。我错过了什么?我有什么可能?非常感谢帮助。
PS:我没有使用任何segues。 My3rdVC被称为是:
let vc = stb.instantiateViewControllerWithIdentifier("My3rdVC") as! My3rdVC
self.navigationController?.pushViewController(vc, animated: true)
我没有使用任何塞格斯。 –
但当然,为你的努力upvote。谢谢 –
你可以在实例化My3rdVC之后传递委托,但在把它推到导航控制器堆栈 – Callam