2011-07-22 5 views
1

Ce code ne fonctionne pas comme requis et ne charge pas les données complètes pour la première fois et fonctionne correctement à la prochaine fois qu'une fois défilée.iPhone: Problème avec tableview

#define ROW_HEIGHT 110 

// Customize the appearance 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; 
} 

Qu'est-ce qui pourrait ne pas fonctionner?

+0

Je refered à ce lien, mais cela n'a pas aidé http://www.iphonedevsdk.com/forum/iphone-sdk-development/15517-best -way-make-multiline-uitableviewcell.html –

+0

Vous devriez ajouter le UILabel au contentView et non à la cellule elle-même, et votre NSLog imprime-t-elle les bons résultats? – Joe

Répondre

1

remplacer cette ligne

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

Pour

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

Merci Got it travail:] –

+0

bienvenue mon pote .... –