繁体   English   中英

在iOS 7的不同部分扩展或折叠行

[英]to expand or collapse rows at different sections in iOS 7

我正在开发一个需要在不同部分扩展折叠行的应用程序。 最初,我尝试使用单个部分扩展折叠行。 现在,我希望在多个部分中进行相同的操作。

这是我的代码

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

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
          NSArray *rate=[mysection objectAtIndex:section];

          return [myrow count];

    }

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (selectedSection==indexPath.section) {


    if(selectedIndex==indexPath.row){
        selectedSection=-1;
        selectedIndex=-1;

        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
        return;

    }
    //user taps on different row
    if(selectedIndex!=indexPath.row){

        NSIndexPath *prevPath=[NSIndexPath indexPathForRow:selectedIndex inSection:selectedSection];

        selectedSection=indexPath.section;

        selectedIndex=indexPath.row;

        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:prevPath] withRowAnimation:UITableViewRowAnimationFade];
        [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];

    }

    selectedIndex=indexPath.row;

    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

    return;
}

else if(selectedSection!=indexPath.section){


    selectedSection=indexPath.section;


    [tableView reloadSections:[NSIndexSet indexSetWithIndex:selectedSection] withRowAnimation:UITableViewRowAnimationFade];

    if(selectedIndex==indexPath.row){
        selectedSection=-1;
        selectedIndex=-1;

        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
        return;

    }
    //user taps on different row
    if(selectedIndex!=indexPath.row){

        NSIndexPath *prevPath=[NSIndexPath indexPathForRow:selectedIndex inSection:selectedSection];

        selectedSection=indexPath.section;

        selectedIndex=indexPath.row;

        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:prevPath] withRowAnimation:UITableViewRowAnimationFade];
        [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];

    }

    selectedIndex=indexPath.row;

    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

selectedSection=indexPath.section;

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];

NSLog(@"%d",selectedSection);
    }

仅应扩大我的行,而不扩大我的部分

请提供一些可能的解决方案。

提前致谢

我的表格视图有多个部分,而我的部分有很多行

点击该部分中的行应展开

在didSelectRowAtIndexPath中,我获得了一个变量的索引路径,该变量可以在整个编码中进行访问,如下所示...

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
selectedCellIndexPath = indexPath;
[tableView reloadData];
}

在Heightforrowatindexpath中

if(selectedCellIndexPath != nil && [selectedCellIndexPath compare:indexPath] ==NSOrderedSame)
    {
        return height;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM