Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Wellington2k

macrumors regular
Original poster
Jun 4, 2011
131
0
Hello.

I have two arrays, one for one section and one for another.

I just want to know how to get them into different sections.

Right now, with the code below, it just shows the same array for both sections.

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    cell.textLabel.text = [array1 objectAtIndex:indexPath.row];
    cell.backgroundColor = [UIColor colorWithWhite:100 alpha:.65f];
    
    return cell;
}
}

I know I have to change the
Code:
cell.textLabel.text = [array1 objectAtIndex:indexPath.row];
to include both arrays, but when I use an array holding both arrays it crashes.

Any help?
 

dantastic

macrumors 6502a
Jan 21, 2011
572
678
I think he means that to use 2 sections you probably want 2 separate arrays and you probably want some simple way of knowing which array you should get your row from depending what section you're in.

Have a look at NSIndexPath, maybe it has something that will make this an easy job.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.