Help with TableView sections

Discussion in 'iOS Programming' started by Wellington2k, Jan 17, 2012.

  1. Wellington2k macrumors regular

    Joined:
    Jun 4, 2011
    #1
    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?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Have you looked into what NSIndexPath contains?
     
  3. Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    NSIndexPath contains more than just a row value.
     
  5. dantastic macrumors 6502

    dantastic

    Joined:
    Jan 21, 2011
    #5
    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.
     
  6. Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011

Share This Page