I know the basic idea of using arrays with cellForRowAtIndexPath using indexPath and row, but I’m unsure of the best way to go through a 2D array. I’ve created a custom cell that accepts 7 different strings into 7 holders and I’ve created a 2D array that has 3 rows of 7 strings. (3×7 2D array). Any suggestions on how to set up the cellForRowAtIndexPath to automatically go through this array?
Let me go into more detail. My multidimensional-array is an array of arrays that contain 7 strings: (“Potato”, “0”, “1”, “2”, “3”, “4”, “5”) My custom cell is all set up with 7 subviews (they work, I tested it with an array). In the same class that I create the custom cell, I’ve created a method that assigns values from the test array to those subviews:
- (void)setMyArray:(NSArray *)myArray
{
NSString *name = [myArray objectAtIndex:0];
[nameLabel setText:name];
[name release];
NSString *numberA = [myArray objectAtIndex:1];
[aLabel setText:numberA];
[numberA release];
NSString *numberB = [myArray objectAtIndex:2];
[bLabel setText:numberB];
[numberB release];
NSString *numberC = [myArray objectAtIndex:3];
[cLabel setText:numberC];
[numberC release];
NSString *numberD = [myArray objectAtIndex:4];
[dLabel setText:numberD];
[numberD release];
NSString *numberE = [myArray objectAtIndex:5];
[eLabel setText:numberE];
[numberE release];
NSString *numberF = [myArray objectAtIndex:6];
[fLabel setText:numberF];
[numberF release];
}
In the viewController, all I have to call is:
[cell setMyArray:testList];
And it works. I’m just not sure how to do it with a 2D array.
I don’t know what exactly your custom cell code looks like, but wouldn’t you just do:
Also, Rob’s right about your memory management. Don’t release the objects as you take them out of the original array.