1
此代碼並不按要求工作,並沒有加載完整的數據的第一次,並從下一次滾動工作正常。iPhone:與桌面視圖問題
#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;
}
什麼可能是錯的?
我refered這個鏈接,但沒有幫助http://www.iphonedevsdk.com/forum/iphone-sdk-development/15517-best -way-make-multiline-uitableviewcell.html –
您應該將UILabel添加到contentView而不是單元本身,並且您的NSLog打印的結果是否正確? – Joe