1
我一直在學習iOS開發並遇到問題。 我有具有UIPickerView
如下:a類(它是隱藏的開始)如何訪問自定義類中的UIPickerView
public class MyController: UIViewController,
UIPickerViewDelegate,
UITableViewDataSource,
UITableViewDelegate {
@IBOutlet var myPickerView: UIPickerView!
}
我有另一個類,我需要訪問此選擇器視圖,並使其可見,當用戶開始編輯的文本字段(它有一個標記= 2)
public class MyClass2: UITableViewCell,
UITextFieldDelegate {
@IBOutlet vat myTextField: UITextField! {didSet {myTextField.delegate = self } }
public func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
if (textField.tag == 2) {
// Somehow access the picker view from the other class and change its property, hidden, to false
}
}
}
謝謝。
你應該閱讀協議和delegati上;然後在創建單元格時將視圖控制器設置爲委託,並根據需要讓單元調用委託方法 – Paulw11