将数据从 UIViesController 传递到 UIView,Swift ios
pass data from UIViesController to UIView, Swift ios
我正在尝试将数据从我的 UIViewcoontroller 传递到我在 swift 上分配给 xib 文件的 UIView 2,我希望 var taxiName 显示在我的 UIView 内的标签上
func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView! {
let infoWindow = NSBundle.mainBundle().loadNibNamed("infoWindow", owner: self, options: nil).first! as! InfoWindow
if (marker.title == "Taxi0")
{
var taxiName = "Taxi0"
return infoWindow
}else if (marker.title == "Taxi1")
{
return infoWindow
}else
{
return nil
}
}
这是我的 UIView
Class InfoWindow: UIView {
@IBOutlet weak var taxiName: UILabel!
var dataPassed: String!
@IBOutlet weak var nextView: UIButton!
}
1) 最简单的方法是:
infoWindow.taxiName.text = taxiName
2) 您可以创建 属性 或一个函数来设置您的变量:
Class InfoWindow: UIView {
@IBOutlet weak var taxiName: UILabel!
@IBOutlet weak var nextView: UIButton!
var dataPassed: String! {
didSet {
taxiName.text = dataPassed
}
}
然后调用
infoWindow.passedData = taxiName
我正在尝试将数据从我的 UIViewcoontroller 传递到我在 swift 上分配给 xib 文件的 UIView 2,我希望 var taxiName 显示在我的 UIView 内的标签上
func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView! {
let infoWindow = NSBundle.mainBundle().loadNibNamed("infoWindow", owner: self, options: nil).first! as! InfoWindow
if (marker.title == "Taxi0")
{
var taxiName = "Taxi0"
return infoWindow
}else if (marker.title == "Taxi1")
{
return infoWindow
}else
{
return nil
}
}
这是我的 UIView
Class InfoWindow: UIView {
@IBOutlet weak var taxiName: UILabel!
var dataPassed: String!
@IBOutlet weak var nextView: UIButton!
}
1) 最简单的方法是:
infoWindow.taxiName.text = taxiName
2) 您可以创建 属性 或一个函数来设置您的变量:
Class InfoWindow: UIView {
@IBOutlet weak var taxiName: UILabel!
@IBOutlet weak var nextView: UIButton!
var dataPassed: String! {
didSet {
taxiName.text = dataPassed
}
}
然后调用
infoWindow.passedData = taxiName