//// section이 복수일때


   //table에 뿌려줄 데이터 sec1, sec2 -> table data

    NSArray *sec1 = [[NSArray alloc] initWithObjects:@"sec1-row1",@"sec1-row2",@"sec1-row3", nil];

    NSArray *sec2 = [[NSArray alloc] initWithObjects:@"sec2-row1",@"sec2-row2", nil];

    

    tabledata = [[NSArray alloc] initWithObjects:sec1,sec2, nil];


...




// cell 세팅

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    

    // Configure the cell...

    

    if(cell == nil){

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }


    if(indexPath.section == 0){

        cell.textLabel.text = [[tabledata objectAtIndex:0] objectAtIndex:indexPath.row];

    }else if(indexPath.section == 1){

        cell.textLabel.text = [[tabledata objectAtIndex:1] objectAtIndex:indexPath.row];

    }

    

    return cell;

}


//section 갯수

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

#warning Potentially incomplete method implementation.

    // Return the number of sections.

    return self.tabledata.count;

}


// Record 갯수 (section별로)

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

#warning Incomplete method implementation.

    // Return the number of rows in the section.

    

    if(section == 0){

        return [[self.tabledata objectAtIndex:0] count];

    }else if(section == 1){

        return [[self.tabledata objectAtIndex:1] count];        

        

    }

    

}



// Header와 Footer

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    if(section == 0){

        return @"section1";

    }else{

        return @"Section2";

    }

}



- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {

    if(section == 0){

        return @"section1";

    }else{

        return @"Section2";

    }

}


Posted by tenn
,