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;
What is output to the console is correct: Tag = 0, 1, 2, 3, etc., but every cell just says the last value in the array. I’ve tried putting the for statement in different locations as well as returning the cell in different blocks. I am sure it is something simple that I am overlooking.
This may only be a partially useful answer, since you have some other issues to consider that I don’t see addressed in the code snippet you’ve shown so far (most notably, that you’ll need some sort of Model, such as a multidimentional array, that holds the spreadsheet data independently of the table view, and also code that will update the Model when the user changes any of the values in the text fields.)
But I think at this point you are just trying to create textfields in your table cells and get some numbers to appear in them. You might try something like this:
Just as a future note, it would have been helpful in your original question to indicate that you are using MDSpreadView