【发布时间】:2013-02-14 13:07:02
【问题描述】:
我以编程方式在 uitableviewcontroller 中创建了一个 uitextview,但我无法编辑该 textview。这是我的表格布局的概述:
第 1 行:UILabel
Row2:不可编辑的 UITextview
第 3 行:UILabel
Row4:可编辑的 UITextview
这就是我正在做的事情:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UILabel *label = nil;
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(indexPath.row%2==0)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, 50)];
[label setBackgroundColor:[self.cellBackgroundColor objectAtIndex:indexPath.row]];
[label setText:[self.celltitle objectAtIndex:indexPath.row]];
label.font=[UIFont fontWithName:[self.cellFontName objectAtIndex:indexPath.row] size:[[self.cellFontSize objectAtIndex:indexPath.row] integerValue]];
label.textAlignment = NSTextAlignmentLeft;
[[cell contentView] addSubview:label];
}
else{
UITextView *messageBox= [[UITextView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, 150)];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.userInteractionEnabled=YES;
if(indexPath.row==3)
{
[messageBox setEditable:YES];
[messageBox setUserInteractionEnabled:YES];
messageBox.delegate=self;
messageBox.editable=YES;
}
[cell.contentView addSubview: messageBox];
}
return cell;}
我还在头文件中设置了 textviewdelegate 和 textviewshouldbeginediting 方法,但是 row4 textview 仍然不可编辑...有什么帮助吗?
【问题讨论】:
-
委托方法有响应吗?
-
No.. 委托方法没有响应..
-
你的 .h 中是否有正确的链接并且你已经添加了
? -
是的,我已经检查了所有内容都已添加...
-
或其他问题可能是您已经将 seteditable 设置为 yes 但显然某些视图与您的 textview 重叠。尝试为所有视图设置不同的背景颜色,然后查看 textview 在单元格上的位置。
标签: ios uitextview uitableview