gpt4 book ai didi

iphone - UIVIEW 子类与 UITextViewDelegate

转载 作者:行者123 更新时间:2023-11-28 17:31:51 25 4
gpt4 key购买 nike

我的 View Controller 变得越来越复杂,所以我决定将一些控件组合在一起并子类化一个 uiview。在我的 View Controller 中,我正在抓取 View :

@property (strong, nonatomic) PostMenuCell *menuCell;
menuCell = [[PostMenuCell alloc] initWithFrame:CGRectMake(3,200,304,96) ];
menuCell.textView.delegate = self;
[self.view addSubview:menuCell];

而且看起来还不错。我有一个 TextView 并在 VC 中使用委托(delegate):

@interface PostPictureViewController : UIViewController <UITextViewDelegate>

我正在尝试使用 TextView 委托(delegate)方法,例如:

- (void)textViewDidBeginEditing:(UITextView *)textView
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

当您单击文本区域时会弹出键盘,但不会使用委托(delegate)方法,因此我无法执行任何操作或关闭键盘。我以为 menuCell.textView.delegate = self;会使 TextView 委托(delegate) VC,但显然不会。

任何指导将不胜感激。

最佳答案

在设置委托(delegate)时检查 textview 是否不为 nil。

关于iphone - UIVIEW 子类与 UITextViewDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10965709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com