私はUITableViewを持っており、テーブルを表示するカスタムセルを作成しました。私は6つのUILablesを表示していますが、表示するレコードは20ですが、スクロールすると非常に遅いです。次のようになります:cellForRowAtIndexPath:すべての物事の私がここでやって(NSDateFormatter、CGMakeRect、floatToStringFormatていますので、スクロールが遅いがあることを実行するためにUITableViewカスタムセルが非常に遅い
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CustomCellIdentifier = @"CustomCellIdentifier";
HistoryCell *cell = (HistoryCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"HistoryCell" owner:nil options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[UITableViewCell class]])
cell = (HistoryCell *) oneObject;
}
NSArray *object;
object = [cours objectForKey: [NSString stringWithFormat:@"%d", indexPath.section]];
History *rowData = [object objectAtIndex:indexPath.row];
if (rowData.month == 99) {
cell.hour.frame = CGRectMake(10, 0, 135, 35);
cell.data.hidden = YES;
cell.hour.textColor = [UIColor blackColor];
cell.hour.font = [UIFont fontWithName:@"Verdana" size:17];
} else {
cell.data.hidden = NO;
cell.hour.frame = CGRectMake(10, 16, 135, 19);
cell.hour.textColor = [UIColor grayColor];
cell.hour.font = [UIFont fontWithName:@"Verdana" size:12];
}
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"d (EEEE)"];
[formatter setLocale:self.selectedLanguageLocale];
NSString *stringFromDate = [formatter stringFromDate:rowData.data];
[formatter release];
cell.data.text = stringFromDate;
cell.hour.text = rowData.ora;
float Var1 = [rowData.Var2 floatValue];
float Var2 = [rowData.Var2 floatValue];
cell.R1.text = [self floatToStringFormat: [rowData.R1 floatValue]];
cell.R2.text = [self floatToStringFormat: [rowData.R2 floatValue]];
if (Var1 <= 0) {
cell.Var1.textColor = [UIColor greenColor];
} else {
cell.Var1.textColor = [UIColor redColor];
}
if (Var2 <= 0) {
cell.Var2.textColor = [UIColor greenColor];
} else {
cell.Var2.textColor = [UIColor redColor];
}
cell.Var1.text = [self floatToStringFormat:Var1];
cell.Var2.text = [self floatToStringFormat:Var2];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
理由...のtableView -
は、これはどのように私です)、または細胞を再利用することに何か問題がありますか?
floatToStringFormat 4つの小数に番号をフォーマットする機能である:CustomCellIdentifier
とBanciHistoryCellIdentifier
:
- (NSString *)floatToStringFormat:(float)number{
NSNumberFormatter *myFloat = [[NSNumberFormatter alloc] init];
[myFloat setFormatterBehavior:NSNumberFormatterBehavior10_4];
[myFloat setNumberStyle:NSNumberFormatterDecimalStyle];
[myFloat setRoundingMode:NSNumberFormatterRoundHalfUp];
[myFloat setMinimumFractionDigits:4];
[myFloat setMaximumFractionDigits:4];
NSString *res = [myFloat stringFromNumber:[NSNumber numberWithFloat:number]];
[myFloat release];
return res;
}
実際には本当ののはBanciHistoryCellIdentifierですが、ここで名前を変更してCustomCellIdentifierに改名して、わかりやすくなりました。この名前を変更することでエスケープしました。 – CristiC