1

皆さんこんにちは、私は自分のアプリで UITableView を作成しました。セルに触れると、私が抱えている問題が拡大します折りたたむのは、別のセルをタップしたときです。

これが私のコードです:

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

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

    if (selectedCellIndexPath) {
        selected = YES;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{        
    if(selectedCellIndexPath != nil  
       && [selectedCellIndexPath compare:indexPath] == NSOrderedSame)  
        return 150;

    return 44;
}
4

4 に答える 4

1

に変更selectedCellIndexPathすることはないnilため、現在選択されている行は、新しい行が選択されるまで変更されません。で、didSelectRowAtIndexPath先頭を次のように変更する必要があります。

if (selectedCellIndexPath == indexPath)
  selectedCellIndexPath = nil;
else
  selectedCellIndexPath = indexPath;
于 2012-06-20T21:17:44.920 に答える
0

行リロード関数を呼び出すと、cellForRowデリゲート関数に入りますか? その場合は、選択した行を確認した後に行を折りたたむ機能を配置する必要があります。

于 2012-06-21T05:24:09.957 に答える
0

折りたたみUITableViewを作成しました

https://github.com/floriankrueger/iOS-Examples--UITableView-Combo-Box/zipball/master http://www.codeproject.com/Articles/240435/Reusable-collapsable-table-view-for-iOS

https://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html

それはうまくいっています..

于 2012-06-21T05:12:28.043 に答える
0
In selectedCellIndexPath you are storing pointer of indexPath. It can change when you reload table, means indexPath object of same cell can be different when you select it second time.
It's safer if you store indexPath.section & indexPath.row 



      -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
        {    
               if(_section == indexPath.section && _row == indexPath.row)
               {
                  _section = -1;
                  _row = -1
               }
               else
               {
                  _section = indexPath.section;
                  _row = indexPath.row;
               }   
               [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];

                if (selectedCellIndexPath) {//change it as per your requirement
                    selected = YES;
                }
         }

      -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
        {        
               if(_section == indexPath.section && _row == indexPath.row)  
                   return 150;

               return 44;
        }
于 2012-06-21T05:03:06.683 に答える