static NSString *cellIdentifier = @"Cell";
NSMutableArray *fields=[[NSMutableArray alloc] init];
MDSpreadViewCell *cell = [aSpreadView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[MDSpreadViewCell alloc] initWithStyle:MDSpreadViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
for (i =0; i < N; i++){
NSLog (@"tag = %i", i);
[fields addObject:[[UITextField alloc] initWithFrame:CGRectMake(10, 10, 185, 30)]];
[[fields objectAtIndex:i] setTag:i];
NSString *John = [NSString stringWithFormat:@"%i", i];
[[fields objectAtIndex:i] setText:John];
[[fields objectAtIndex:i] setBackgroundColor:[UIColor redColor]];
[[fields objectAtIndex:i] setDelegate:self];
[[fields objectAtIndex:i] setUserInteractionEnabled:TRUE];
viewWithTag:i]).text;
[cell addSubview:[fields objectAtIndex:i]];
}
return cell;
输出到控制台的内容是正确的:Tag = 0、1、2、3 等,但每个单元格只表示数组中的最后一个值。我尝试将 for 语句放在不同的位置,并在不同的块中返回单元格。我确信这是我忽略的简单事情。