开发者

iPhone: Problem with tableview

开发者 https://www.devze.com 2023-03-22 01:59 出处:网络
This code doesnt work as required and doesnt load full data for the first time and works fine from the next time once scrolled.

This code doesnt work as required and doesnt load full data for the first time and works fine from the next time once scrolled.

#define ROW_HEIGHT 110

// Customize the a开发者_开发百科ppearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog( @"Setting table text." );

static NSString *CellIdentifier = @"Transaction";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    [cell addSubview:[[UILabel alloc] initWithFrame:CGRectMake(40.0, 0.0, 280.0, ROW_HEIGHT - 1)]];
}

NSUInteger row = [indexPath row];

NSLog( @"Table cell text: %@", [[transactionHistory objectAtIndex:row] description] );

UILabel *labelText = [[cell subviews] lastObject];
labelText.text = [[transactionHistory objectAtIndex:row] description];
labelText.font = [UIFont systemFontOfSize:14];
labelText.lineBreakMode = UILineBreakModeWordWrap;
labelText.numberOfLines = 5;    

return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return ROW_HEIGHT;
}

What could be wrong?


replace this line

    [cell addSubview:[[UILabel alloc] initWithFrame:CGRectMake(40.0, 0.0, 280.0, ROW_HEIGHT - 1)]];

To

   [cell.contentView addSubview:[[UILabel alloc] initWithFrame:CGRectMake(40.0, 0.0, 280.0, ROW_HEIGHT - 1)]];
0

精彩评论

暂无评论...
验证码 换一张
取 消