-1
Я создаю представления кнопок в раскадровке, которые открывают URL-адрес, где URL-адрес может быть установлен в Инспекторе как @IBInspectable для каждой кнопки.Доступ к переменной @IBInspectpect от кнопки @IBAction
Моя проблема в том, что я могу подключить действие кнопки только к @IBAction в ViewController, из которого переменные или функции пользовательского класса CustomButton кажутся недоступными.
ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBAction func openURL(sender: CustomButton) {
let theURL = self.myURL; // accesses parent ViewController, not CustomButton, where the variable is defined for this view
UIApplication.sharedApplication().openURL(NSURL(string: theURL)!)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Button.swift
import UIKit
class CustomButton: UIButton {
@IBInspectable var myURL: String?
@IBInspectable var myPhone: String?
}
Спросите себя, что означает 'self'. – matt