我正在构建自定义UIView,它接受输入字段VOID InitializeTitleSpecificHooks(PLDR_DATA_TABLE_ENTRY ModuleHandle)
或UITextField
的初始化数组。我需要在输入字段开始编辑时通知此自定义视图,而不设置代理。
UITextView
中,我通过添加UITextField
属性的观察者提出了一个想法。你有其他想法吗?editing
找不到editing
所以我应该怎么做。我的想法是,我需要将此自定义视图作为独立视图,让用户可以在UITextView
答案 0 :(得分:2)
另一种方法是观察use App\UserMailer as Mailer ;
class TestController extends Controller
{
protected $mailer;
public function __construct(Mailer $mailer)
{
$this->mailer;
}
public function testMailer()
{
$this->mailer->welcome()->sendTo(1);
return 'done';
}
的通知UITextView
和
UITextViewTextDidBeginEditingNotification
的通知UITextField
答案 1 :(得分:0)
这是一种方法,可以允许向此自定义UIView发送通知,而无需将其设置为委托:
import UIKit
class SelfAwareTextField : UITextField, UITextFieldDelegate {
//
// Other delegate for this textfield
//
var otherDelegate: UITextFieldDelegate? = nil;
//
// Set weak reference to parent UIView
//
weak var parentView: UIView!
//
// Set the initializer
//
init(parentView pv: UIView, frame: CGRect) {
parentView = pv;
super.init(frame: frame);
//
// Do some custom initialization...
//
// Make this textfield a delegate to itself
self.delegate = self;
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setDelegate( delegate _otherDelegate: UITextFieldDelegate ){
otherDelegate = _otherDelegate;
}
//
// Write the textFieldDidBeginEditing method such that it
// also calls the otherDelegate in the event it exists
// and has this method defined
//
func textFieldDidBeginEditing(_ textField: UITextField){
//
// Do stuff based on this textfield knowing it is starting to be used
//
// ....
//
//
// Do stuff for parent UIView
// ...
// (parentView as! CustomView).notified() // or something like this
//
//
// Do stuff for the other delegate
//
otherDelegate?.textFieldDidBeginEditing?(textField);
}
// Do similar thing as above for other methods in UITextFieldDelegate protocol
}
我们的想法是,您将此文本字段作为自己的委托,以便知道何时调用每个委托方法。然后在每次调用这些委托方法时,您可以使用自定义UIView和您希望与此文本字段关联的任何其他委托执行某些操作。
答案 2 :(得分:-1)
我提出了一个解决方案,我使用UIKeyboardWillShowNotification
在键盘即将显示时接收通知,然后遍历我拥有的字段并检查isFirstResponder()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillBeShown:", name: UIKeyboardWillShowNotification, object: nil)
然后:
@objc private func keyboardWillBeShown(notification:NSNotification){
for field in fields{
if field.isFirstResponder(){
// handle begin editing here
}
}
}