我在UITableView中绘制自定义视图有一个时髦的问题。我的自定义视图的drawRect函数(称为ChatBubbleView)仅绘制了一个常量大小的矩形。UITableView在5个单元格后失败的自定义绘图
我在ChatBubbleView的drawRect函数中有一个NSLog调试语句。前5次我给UITableView添加一个单元格,所有东西都很好地绘制,并且我看到了NSLog语句触发器。然而,5之后,绘图变得乱码,我不再看到调试声明。
我完全不知所措,我很感激您可能提供的任何帮助。提前致谢!
这是在UITableView上调用reloadData时调用的函数。
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (forumMode) {
//This part works, ignore
} else {
ChatBubbleView* chatBubble = nil;
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero
reuseIdentifier:CellIdentifier] autorelease];
// Add the bubble
chatBubble = [[[ChatBubbleView alloc] init] autorelease];
chatBubble.tag = BUBBLEVIEW_TAG;
[cell.contentView addSubview:chatBubble];
} else {
// Reuse old views
chatBubble = (ChatBubbleView*)[cell.contentView viewWithTag: BUBBLEVIEW_TAG];
}
chatBubble.labelSize = CGSizeMake(50, 18);
chatBubble.frame = CGRectMake(0, 0, chatBubble.labelSize.width, chatBubble.labelSize.height);
}
return cell;
}
编辑:我要补充一点,即重新加载UITableView的功能如下:
-(IBAction) btnAdd:(id) sender {
[listOfMessages addObject:textView.text];
[self.tableView reloadData];
}
编辑2:我发现,在细胞中的自定义视图有时重绘自己,当我滚动细胞进出视野。看起来,tableview刷新改变了自定义视图的参数。
我一定会做到这一点,谢谢。 BOOL值forumMode在viewDidLoad函数中设置为false,并且永远不会更改,所以我知道if(forumMode)语句永远不会计算为true。这就是为什么我把忽略评论放在那里。 – CaptainStiggz 2010-11-08 16:51:55