iphone - UITableViewCell 中的 UITextView

标签 iphone objective-c ios uitableview uitextview

我在自定义 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;

最佳答案

设置self.textView.contentInset = UIEdgeInsetsZero;

关于iphone - UITableViewCell 中的 UITextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7022205/

相关文章:

iphone - 如何以编程方式暂停 NSTimer?

选择取消按钮错误后的 iOS 11 UIImagePickerController

ios - CALayer上的边框显示不正确

android - 为什么使用单线程模型作为主线程来更新 UI?

ios - UIScrollView 不工作/宽度和高度错误

iphone - self.window.rootViewController 与窗口 addSubview

iphone - 如何让 Cocoa 明白我的 iPhone 应用程序不是英文的?

ios - iCarousel 上的缩放变换显示屏幕外区域

objective-c - 获取字体的最大高度

ios - NSDictionary 中值的总和