Search code examples
iphoneobjective-cxcodeuitableviewsections

UITableView Putting array objects into sections


Hey guys I need to know who to put these array objects into two separate sections, that means one section for the red cell and another section for the blue cell. Would really appreciate your help been stuck on this all day now. Here is my code:

-(void)viewDidLoad {

    [super viewDidLoad];
    //Initialize the array.
    array = [[NSMutableArray alloc] init];
    [array addObject:@"Red"];
    [array addObject:@"Blue"];

    self.ViewTable.backgroundColor = [UIColor clearColor];    
}

Solution

  • - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    // Return the number of sections.
    return 2; // This returns 2 sections
    }
    

    Updated: In the cellForRowAtIndexPath

    NSInteger section = [IndexPath section];
    
    if  (section == 0)
    
      // write your code for red here
    
    if  (section == 1)
    
      // write your code for blue here