6

詳細を表示するために、クリックでセルを拡張する必要があるアプリケーションを実行しています。カスタムセルを使用して、UItableview に追加しました。セルをクリックすると正常にアニメーション化されて下に移動し、もう一度クリックすると上に移動します。これは、セルの高さを変更することで行われます。実際のカスタム セル サイズは、通常表示されるセルよりも大きくなります。セルをクリックすると、セル全体が表示されます。私が抱えている唯一の問題は、データのオーバーフローです。セルが選択されていない場合、これらのデータは非表示にする必要があります。選択されている場合にのみ、これらのデータが表示されます。

別のアーティカルを参照しましたが、カラー設定の境界を変更しようとしましたが、うまくいきませんでした。この質問iphone uitablecellview overflowで尋ねられたのと同じ種類の問題があり、答えを試しましたが、うまくいきませんでした。

私が必要とするのは、拡張されていないときにカスタムセルの下部を非表示にし、拡張されたときに表示する方法です...!

これらは私のスクリーンショットです

読み込まれると ロードされ セルをクリックすると たとき セルをクリックした 2番目のセルをクリックすると とき] 2番目 展開されたセルをクリックすると
のセルをクリックしたとき すでに展開されているセルをクリックしたとき これらは私が使用したコードスニップです....

// Declaring the SearchResultTable.
    CGRect filterFrame = CGRectMake(0,31, 320, 400);
    self.searchResultTable = [[UITableView alloc] initWithFrame:filterFrame];
    self.searchResultTable.dataSource = self;
    self.searchResultTable.delegate = self;
    self.searchResultTable.backgroundColor = [UIColor whiteColor];
    self.searchResultTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.searchResultTable.separatorColor = [UIColor lightGrayColor];
    [self.view addSubview:self.searchResultTable];

//Adding cells
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"ExpandedSearchResultTableCell";


    ExpandedSearchResultTableCell *cell = (ExpandedSearchResultTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    if (cell == nil)
    {
        cell.contentView.clipsToBounds = YES;
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ExpandedSearchResultTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];


    }

    cell.productNameLable.text = @"Only this should be shown";
    cell.productListLabel.text = @"This Should be hidden.. Only shown when expanded";
    cell.productApplicationLable.text=@"This Should be hidden.. Only shown when expanded";
    cell.productTargetLable.text= @"This Should be hidden.. Only shown when expanded";
    cell.productQuantityLable.text=@"This Should be hidden.. Only shown when expanded";
    cell.productReactivityLable.text=@"This Should be hidden.. Only shown when expanded";;


    return cell;
}


//on click event
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {




    // Deselect cell
    [tableView deselectRowAtIndexPath:indexPath animated:TRUE];

    // Toggle 'selected' state
    BOOL isSelected = ![self cellIsSelected:indexPath];

    // Store cell 'selected' state keyed on indexPath
    NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
    [selectedIndexes setObject:selectedIndex forKey:indexPath]; 

    // This is where magic happens...
    [searchResultTable beginUpdates];
    [searchResultTable endUpdates];
}

//Getting the height depending on expanded or not
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    // If our cell is selected, return double height
    if([self cellIsSelected:indexPath]) {
        return kCellHeight * 3.0;
    }

    // Cell isn't selected so return single height
    return kCellHeight;
}
4

3 に答える 3

1

わかりました、1 つのフラグと、didSelectRowAtIndexPath の cellForRowAtIndexPath セルへの参照を使用して、それを実行しました。そして、折りたたみとストレッチに応じてラベルを表示および非表示に設定します。セルが選択されているかどうかに応じてフラグが更新されます...!!

みんなを助けてくれてありがとう..!

于 2012-08-29T16:42:29.077 に答える
1

プレーンなテーブルビュータイプでセル展開をお探しの方は、

セルが拡大するアニメーション付きの iPhone UITableView

また、グループ化されたテーブルビューを使用していて、セクション ヘッダーの選択を拡張したい場合は、

テーブル ビューのアニメーションとジェスチャー

于 2012-08-29T12:10:42.340 に答える
0

おっと、大量のコードが投稿を汚しました。

私はあなたのコードを調べていません。

ロジックを説明します。

  1. これだけが表示され、indexpath.row = 0; に入ります。
  2. セクション内の行数は、選択されている場合は表示されるセルの数 + 1、それ以外の場合は 1 になります。
cell.productNameLable.text = @"Only this should be shown";
cell.productListLabel.text = @"This Should be hidden.. Only shown when expanded";
cell.productApplicationLable.text=@"This Should be hidden.. Only shown when expanded";
cell.productTargetLable.text= @"This Should be hidden.. Only shown when expanded";
cell.productQuantityLable.text=@"This Should be hidden.. Only shown when expanded";
cell.productReactivityLable.text=@"This Should be hidden.. Only shown when expanded";;

これにより、コードが汚れます。すべてのデータを 1 つのセルに表示し、1 つのセクションを選択したときに 1 つのセルのみが追加される場合は、これらすべてを別のセルに追加することをお勧めします。

なぜこれらの長いコーディングを行っているのか、まだ混乱しています。より良い説明については、この回答を参照してください

于 2012-08-29T12:57:05.040 に答える