我创建了2个视图,一个是使用协议和委托.对于第一个视图,不调用Delegate函数.
import UIKit class NextViewController: UIViewController,DurationSelectDelegate { //var secondController: DurationDel? var secondController: DurationDel = DurationDel() @IBAction func Next(sender : AnyObject) { let nextViewController = DurationDel(nibName: "DurationDel",bundle: nil) self.navigationController.pushViewController(nextViewController,animated: true) } override func viewDidLoad() { super.viewDidLoad() secondController.delegate=self } func DurationSelected() { println("SUCCESS") } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // dispose of any resources that can be recreated. } }
我的SecondView控制器:我在这里创建委托.
import UIKit protocol DurationSelectDelegate { func DurationSelected() } class DurationDel: UIViewController { var delegate: DurationSelectDelegate? @IBAction func PrevIoUs(sender : AnyObject) { //let game = DurationSelectDelegate() delegate?.DurationSelected() self.navigationController.popViewControllerAnimated(true) } override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // dispose of any resources that can be recreated. } }
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。