Iphone 我想生成两个具有4行和2行的可扩展部分

Iphone 我想生成两个具有4行和2行的可扩展部分,iphone,ios,objective-c,Iphone,Ios,Objective C,在下面的示例中,第1节和第2节是可展开的。但是每个可展开的节都有4个单元格。我需要一种方法来适应第1节中的4行和第2节中的2行。第一个方法指定要展开的行,其余的是tableview委托和数据源方法 - (BOOL)tableView:(UITableView *)tableView canCollapseSection:(NSInteger)section { if (section>0 && section<3) return YES;

在下面的示例中,第1节和第2节是可展开的。但是每个可展开的节都有4个单元格。我需要一种方法来适应第1节中的4行和第2节中的2行。第一个方法指定要展开的行,其余的是tableview委托和数据源方法

 - (BOOL)tableView:(UITableView *)tableView canCollapseSection:(NSInteger)section
    {
        if (section>0 && section<3) return YES;

        return NO;
    }

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





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

    if ([self tableView:tableView canCollapseSection:section])
    {

        if ([expandedSections containsIndex:section])
        {

            NSLog(@"section number:%d",section);
            return 3; // return rows when expanded

        }
            return 1; // only top row showing

    }

    // Return the number of rows in the section.
    return 1;


}



- (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];
    }

    // Configure the cell...

    if ([self tableView:tableView canCollapseSection:indexPath.section])
    {
        if (!indexPath.row)
        {
            // first row
            cell.textLabel.text = @"Expandable"; // only top row showing

            if ([expandedSections containsIndex:indexPath.section])
            {
            //some code
            }
            else
            {
                //some code
            }
        }
        else
        {
            // all other rows
            cell.textLabel.text = @"Some Detail";
            cell.accessoryView = nil;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
    }
    else
    {
        cell.accessoryView = nil;
        cell.textLabel.text = @"Normal Cell";

    }

    return cell;
}
-(BOOL)tableView:(UITableView*)tableView可以合并设置:(NSInteger)部分
{

if(section>0&§ion在numberOfRowsInSection方法中返回正确的行数

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([self tableView:tableView canCollapseSection:section])
    {
        if ([expandedSections containsIndex:section])
        {
            NSLog(@"section number:%d",section);
            // -------------- UPDATE HERE --------------
            return (indexPath.section == 1 ? 4 : 2); // return rows when expanded
        }
        return 1; // only top row showing
    }
    // Return the number of rows in the section.
    return 1;
}