我有一個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