我有一个MainViewController.swift,它连接到一个Xib文件(称为MainViewController)。 MainViewController连接到一个MenuViewController.swift及其Xib(称为MenuViewController)。该MainViewController使用下面的代码调用MenuViewContoller,Swift - 如何从故事板中的视图控制器加载xib文件?
override func viewDidLoad() {
super.viewDidLoad()
...
menuBtn.addTarget(self, action: #selector(callMenuModal), forControlEvents: .TouchUpInside)
....
}
func callMenuModal() {
let menuVC = MenuViewController()
menuVC.delegate = self
menuVC.modalPresentationStyle = .OverCurrentContext
presentViewController(menuVC, animated: false, completion: nil)
}
.......
func backFromMenu() {
self.dismissViewControllerAnimated(true, completion: nil)
}
...
...
我的朋友们做了一个故事板有很多塞格斯和ViewControllers的。
当从故事板上的ViewController按下按钮时,我必须现在加载我的.xib文件及其相应的视图控制器。我看到一个解决方案的高和低,并找不到一个。
以前我直接从AppDelegate调用我的xib,所以我不必做任何事情。我曾在故事板上只有一个视图控制器,我在委托中使用的代码下面给出了整个应用程序的应用程序委托,
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds)
let mainViewController = MainViewController(nibName: "MainViewController", bundle: nil)
window?.rootViewController = mainViewController
window?.makeKeyAndVisible()
return true
}
........rest of app delegate....
但我不知道如何加载厦门国际银行文件,从故事板中的不同视图控制器或从ViewController中按下按钮(IBAction)。
如果你不能做这个简单的任务,那么你需要阅读和理解更多[Apple提供的基本教程。](https://developer.apple.com/library/prerelease/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/) – Jeff