【发布时间】:2016-04-14 06:47:09
【问题描述】:
我尝试使用委托从自定义单元格加载视图控制器。但我从设置委托中得到零! 如果有人可以提供帮助,这是一个示例! 1. 在单元格中
protocol hotelFindDelegate{
func modalDidFinished(modalText: String)
}
class hotelFindCell: UITableViewCell {
var delegate:hotelFindDelegate?
@IBAction func findButton(sender: AnyObject) {
self.delegate!.modalDidFinished("HELLO")
print("Damn nothing works")
}
2。在主视图中
class MainViewController:hotelFindDelegate {
let modalView = hotelFindCell()
override func viewDidLoad() {
super.viewDidLoad()
self.modalView?.delegate = self
}
func modalDidFinished(modalText: String){
let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("HotelListVC") as UIViewController
self.presentViewController(viewController, animated: false, completion: nil)
self.modalView.delegate = self
print(modalText)
}
【问题讨论】:
-
你想从 XIB 加载 VC..?您给定的代码与您的问题不匹配。
-
是的!我正在尝试使用代表。不要介意代码。
-
如果你使用委托或做其他事情没关系,但你的代码至少应该符合你的要求。首先,您决定要从 XIB 或情节提要加载视图控制器..?
-
从xib加载viewcontroller