-1
私はストーリーボードにURLを開くボタンビューを作成しています。ここでURLはInspectorで@IBInspectableボタンとして設定できます。ボタンの@IBInspectable変数にアクセスする@IBAction
私の問題は、カスタムクラスCustomButtonの変数や関数がアクセスできないように見えるViewControllerの@IBActionにのみボタンのアクションを接続できることです。
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?
}
「自己」が何を意味するのか自分自身に尋ねます。 – matt