ios - 如何在 XIB 中调用 UITextField 的委托(delegate)方法?

标签 ios objective-c xib uitextviewdelegate

我有一个包含在自定义 UIViewControllerAlarm 中的 XIB ProfileViewProfileView 有一个 subview UITextView,我想从我的自定义类 Alarm 调用 UITextView 委托(delegate)方法,而不是 ProfileView 因为我所有关于 UITextView 文本的逻辑都在我的 Alarm 类中。所以我的问题是:如果 UITextViewProfileView 的 subview ,我可以从我的 Alarm 类调用 UITextView 委托(delegate)方法吗>?换句话说,我可以将 UITextView 委托(delegate)设置为 Alarm 而不是 self 吗?

enter image description here

最佳答案

  • 连接并使 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/

相关文章:

iphone - 从 Storyboard 到 XIB 的 Segue

ios - 如何使用自动布局调整图像按钮的大小?

ios - 在播放 iOS 时从 HLS 流(视频)中提取/录制音频

ios - 单击由 nib 制作的自定义表格单元格时更改图像

objective-c - 为什么变量不保留在 Asset-Library block 之外?

iphone - iOS:如何生成 8 个唯一的随机整数?

cocoa - 本地化基于 xib 的现代 Mac 应用程序

iphone - Cocos2d 有哪些好的测试工具?

ios - 需要有关多个 subview Controller 的建议

ios - NSTimer 倒计时无法正常运行