UITableViewCell 内的 UITextView

发布于 2024-11-29 01:13:57 字数 1843 浏览 1 评论 0原文

我在自定义 UITableViewCell 中有一个 UITextView。我遇到的问题与 resignFirstResponder 有关。当调用 resignFirstResponder 且 UIkeyboard 关闭时,UITextView 向上滚动一行,这使得输入在单元格顶部仅一半可见。

当我创建 UITextView 时,我是否遗漏了以下代码中的某些内容?

            if (indexPath.row == 0) {
            // Load the cell with the comment textView 

            cell = (DetailCellViewController *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier3];
            if (cell == nil) {
                NSArray *topLevelObjects = [[NSBundle mainBundle]
                                            loadNibNamed:@"DetailCellView3" 
                                            owner:nil 
                                            options:nil];

                for (id currentObject in topLevelObjects) {
                    if ([currentObject isKindOfClass:[UITableViewCell class]]) {
                        cell = (DetailCellViewController *) currentObject;
                        break;
                    }
                }
            }       
            self.textView = [[UITextView alloc] initWithFrame:cell.contentView.bounds];
            self.textView.backgroundColor = [UIColor clearColor];
            self.textView.textColor = [UIColor blackColor]; 
            self.textView.returnKeyType = UIReturnKeySend;
            self.textView.enablesReturnKeyAutomatically = YES;
            self.textView.editable = YES;
            self.textView.scrollEnabled = YES;
            self.textView.opaque =YES;
            self.textView.clipsToBounds = YES;
            self.textView.autocorrectionType = UITextAutocorrectionTypeNo;
            self.textView.delegate = self;
            self.textView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
            [cell.contentView addSubview:textView];
            [textView release];

            return cell;

I have a UITextView inside a custom UITableViewCell. The problem im having is related to resignFirstResponder. When resignFirstResponder is called and the UIkeyboard is dismissed the UITextView scrolls up one line which makes the input only half visible at the top of the cell.

Have I missed something in the following code when I create the UITextView?

            if (indexPath.row == 0) {
            // Load the cell with the comment textView 

            cell = (DetailCellViewController *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier3];
            if (cell == nil) {
                NSArray *topLevelObjects = [[NSBundle mainBundle]
                                            loadNibNamed:@"DetailCellView3" 
                                            owner:nil 
                                            options:nil];

                for (id currentObject in topLevelObjects) {
                    if ([currentObject isKindOfClass:[UITableViewCell class]]) {
                        cell = (DetailCellViewController *) currentObject;
                        break;
                    }
                }
            }       
            self.textView = [[UITextView alloc] initWithFrame:cell.contentView.bounds];
            self.textView.backgroundColor = [UIColor clearColor];
            self.textView.textColor = [UIColor blackColor]; 
            self.textView.returnKeyType = UIReturnKeySend;
            self.textView.enablesReturnKeyAutomatically = YES;
            self.textView.editable = YES;
            self.textView.scrollEnabled = YES;
            self.textView.opaque =YES;
            self.textView.clipsToBounds = YES;
            self.textView.autocorrectionType = UITextAutocorrectionTypeNo;
            self.textView.delegate = self;
            self.textView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
            [cell.contentView addSubview:textView];
            [textView release];

            return cell;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小忆控 2024-12-06 01:13:57

设置 self.textView.contentInset = UIEdgeInsetsZero;

Set self.textView.contentInset = UIEdgeInsetsZero;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文