簡體   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