我在尝试从父视图控制器访问.xib文件中的元素时遇到问题。我的代码如下:
GraphScrollViewController.swift
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(1800, 1200, 192d, 192d, PixelFormats.Pbgra32);
RecentWeekGraphViewController.swift
class GraphScrollViewController: UIViewController {
var graphScrollMenu: CAPSPageMenu?
var controllerArray: [UIViewController] = []
override func viewDidLoad() {
super.viewDidLoad()
var weekViewController : RecentWeekGraphViewController = RecentWeekGraphViewController(nibName: "RecentRulesWeekGraphViewController", bundle: nil)
weekViewController.title = "Week"
controllerArray.append(weekViewController)
var monthViewController : RecentMonthGraphViewController = RecentMonthGraphViewController(nibName: "RecentMonthGraphViewController", bundle: nil)
monthViewController.title = "Month"
controllerArray.append(monthViewController)
var parameters: [CAPSPageMenuOption] = [
.ScrollMenuBackgroundColor(UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 0)),
.ViewBackgroundColor(UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 0)),
.SelectionIndicatorColor(UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1)),
.BottomMenuHairlineColor(UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 0)),
.UnselectedMenuItemLabelColor(UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 0.5)),
.MenuItemFont(UIFont(name: "Avenir-Book", size: 15.0)!),
.MenuHeight(40.0),
.MenuItemWidth(90.0),
.CenterMenuItems(true)
]
graphScrollMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, 0.0, self.view.frame.width, self.view.frame.height), pageMenuOptions: parameters)
self.view.addSubview(graphScrollMenu!.view)
}
}
当我尝试使用weekViewController.xibTestLabel.text =&#34时,从GraphScrollView.swift设置xibTestLabel文本;一些文字"我明白了:
class RecentWeekGraphViewController: UIViewController {
@IBOutlet weak var xibTestLabel: UILabel!
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
我的网点似乎都连接正确。
由于
答案 0 :(得分:0)
在Xcode7 beta 4中测试过。 创建一个字符串变量并从外部分配值并在viewdidload
上设置它var weekViewController : RecentWeekGraphViewController = RecentWeekGraphViewController(nibName: "RecentRulesWeekGraphViewController", bundle: nil)
weekViewController.title = "Week"
weekViewController.labeltext = "Title"
在RecentWeekGraphViewController.swift
中 var labeltext: String!
override func viewDidLoad() {
super.viewDidLoad()
self.labelTitle.text = labeltext
// Do any additional setup after loading the view.
}
问题是IBOutlet在呈现viewcontroller时会连接。如果要直接访问IBOutlet,可以在presentViewController内部完成处理程序
self.presentViewController(weekViewController, animated: true, completion: { weekViewController.labelTitle.text = "title two"
});