【发布时间】:2016-01-07 07:04:17
【问题描述】:
我的项目中有一个自定义选项卡,它位于应用程序的每个屏幕上,因此我制作了自定义 UIView 类和 xib 文件并在其中添加了按钮。现在我想要我的按钮在具有不同story board id 的不同屏幕上进行导航。但是我不能从UIView 类中调用presentViewController。以前我在extension 类中自定义函数以在屏幕之间导航,但UIView 类也不能调用该函数。
import UIKit
@IBDesignable class tab: UIView {
var view: UIView!
@IBAction func btn1(sender: UIButton) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("6")
self.presentViewController(vc, animated: true, completion: nil)
}
override init(frame: CGRect) {
super.init(frame: frame)
xibSetup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
xibSetup()
}
func xibSetup() {
view = loadViewFromNib()
view.frame = bounds
view.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
addSubview(view)
}
func loadViewFromNib() -> UIView {
let bundle = NSBundle(forClass: self.dynamicType)
let nib = UINib(nibName: "tab", bundle: bundle)
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
return view
}
}
【问题讨论】:
标签: ios swift uiview presentviewcontroller