我有一个包含在自定义 UIViewController
类 Alarm
中的 XIB ProfileView
。 ProfileView
有一个 subview UITextView
,我想从我的自定义类 Alarm
调用 UITextView
委托(delegate)方法,而不是 ProfileView
因为我所有关于 UITextView
文本的逻辑都在我的 Alarm
类中。所以我的问题是:如果 UITextView
是 ProfileView
的 subview ,我可以从我的 Alarm
类调用 UITextView
委托(delegate)方法吗>?换句话说,我可以将 UITextView
委托(delegate)设置为 Alarm
而不是 self
吗?
最佳答案
连接并使
UITextView
成为ProfileView
的公共(public)属性@interface ProfileView : UIView @property (weak, nonatomic) IBOutlet UITextView *textView; @end
在您的
Alarm
类中,设置self.profileView.textView.delegate = self
并实现您需要的功能,或者如果profileView
不是Alarm
的属性,请在初始化后设置委托(delegate)。@interface Alert : UIViewController <UITextViewDelegate> @property (nonatomic, strong) ProfileView* profileView; @end // In |viewDidLoad| or anywhere after you initialize |_profileView| self.profileView.textView.delegate = self;
关于ios - 如何在 XIB 中调用 UITextField 的委托(delegate)方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50361069/