这是我的cellForRowAtIndexPath
功能。我无法让setText
标签生效。你能帮帮我吗?
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UILabel *messageLabel = nil;
int row = [indexPath row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, ROWHEIGHT) reuseIdentifier:CellIdentifier];
messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 5, 240, 60)];
[messageLabel setFont:[UIFont fontWithName:@"ArialMT" size:12]];
[messageLabel setTextColor:[UIColor blackColor]];
[messageLabel setBackgroundColor:[UIColor clearColor]];
[messageLabel setNumberOfLines:3];
[messageLabel setLineBreakMode:UILineBreakModeWordWrap];
[messageLabel setTag: messageTag];
[cell.contentView addSubview:messageLabel];
}
else{
messageLabel = (UILabel *)[cell viewWithTag:messageTag];
}
[messageLabel setText:[[[aSingleton wallItemArray] objectAtIndex:row] message]];
NSLog(@" -- > at row %d, message: %@", row, [[[aSingleton wallItemArray] objectAtIndex:row] message]);
return cell;
}
答案 0 :(得分:2)
您正在将UILabel添加到单元格的contentView
,但要求单元格查看该视图。
你试过了吗?
messageLabel = (UILabel *)[cell.contentView viewWithTag:messageTag];
编辑:此外,你有两个内存泄漏 - 你是alloc
UITableViewCell和UILabel而没有(自动)在任何地方发布它们。