UITableViewCell 内的 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;
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置 self.textView.contentInset = UIEdgeInsetsZero;
Set
self.textView.contentInset = UIEdgeInsetsZero;