swift - 如何从 xib 文件加载 View Controller ?

标签 swift delegates xib

我尝试使用委托(delegate)从自定义单元格加载 View Controller 。但是我从设置的委托(delegate)中得到零! 这是一个示例,如果有人可以提供帮助! 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)  
}

最佳答案

To load view controller from XIB do the following steps.

let settingVC : SettingsViewController = SettingsViewController(nibName :"SettingsViewController",bundle : nil)

later on you can push the same view controller object like

self.navigationController?.pushViewController(settingsVC, animated: true)

关于swift - 如何从 xib 文件加载 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36615659/

相关文章:

php - 服务器端 Apple 推送通知

ios - UIPageViewController:表格垂直滚动不起作用

ios - 在 didSelectItemAt 中实现委托(delegate)

ios - 注销时重置 Storyboard

ios - 为 iOS 7 和 iOS 8 的 Root View Controller 获取不同的框架

ios - 快速添加基于模板的 UIView?

ios - Swift:使用 GCDAsyncUdpSocket 接收 UDP

jQuery 委托(delegate)关闭 Boxy 对话框

ios - 为什么即使我完成了所有必要的步骤,我的代理人也没有工作?

objective-c - 当我打开特定的 XIB 文件时 Xcode 崩溃