3

私のコードの一部で、私は呼び出します

UITableViewCell *cell = (UITableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];

セルの数を取得してから、アルファを .35 に変更します。これは機能し、細胞は色あせて見えます。

ただし、テーブルビューをスクロールすると、ウィンドウの外に移動してから戻るセルがフェードしなくなりました。これは、cellForRowAtIndexPath で無効な各行のアルファが .35 に設定されていても発生します。

cellForRowAtIndexPath でセルを返す直前にログに記録します

NSLog(@"%f", cell.alpha);

そして、それは.35を返します

しかし、スクロール後にセルがフェードしていませんか?表示される前に、アルファが魔法のように 1 に戻されたかのように見えます。

以下は、セクションクラスでの cellForRowAtIndexPath の実装です

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;

if ([self disabled]) 
{
    cell = [SectionedTableViewController tableView:tableView dequeueReusableCellWithIdentifier:@"CellDisabled" style:UITableViewCellStyleDefault];
    cell.alpha = .35;
}
else
{
    cell = [SectionedTableViewController tableView:tableView dequeueReusableCellWithIdentifier:@"CellEnabled" style:UITableViewCellStyleDefault];
    cell.alpha = 1;
}

cell.selectionStyle = UITableViewCellSelectionStyleNone;

//if-else block that only sets labels is here omitted

if (cell.textLabel.text == [[cs objectAtIndex:[self c]] type])
{
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
}

NSLog(@"%f", cell.alpha);

return cell;

}

そして、これらのセクションを調整するView Controllerは、次のようにそれらからセルを取得します:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Alpha: %f", [[[self sections] objectAtIndex:indexPath.section] tableView:tableView cellForRowAtIndexPath:indexPath].alpha);
    return [[[self sections] objectAtIndex:indexPath.section] tableView:tableView cellForRowAtIndexPath:indexPath];
}

(そして NSLog は適切なアルファ値を記録しています)

4

3 に答える 3

14

すべてのサブビューをセルの contentView に追加し、 で次の文字列を使用します-cellForRowAtIndexPath

cell.contentView.alpha = {needed_value};

あなたのために働きます。

于 2012-10-29T10:05:24.537 に答える
2

この問題は、テーブル ビューでセルが再利用されていることが原因である可能性があります。これを行うには、より良い方法があります。

ビュー コントローラで NSMutableDictionary を作成し、フェードするインデックスのキーを設定するだけです。

次に、cellForRowAtIndexPath で、セルの設定中に、インデックスが辞書のキーとして存在するかどうかに基づいてアルファを設定します。

このソリューションは、奇妙な動作なしで機能します。

于 2012-06-29T22:37:12.193 に答える
1

アルファ値も設定していることを確認してくださいcell.contentViewtableView:willDisplayCell:forRowAtIndexPath:また、iOS 7 では機能しない可能性があるため、アルファを設定します

于 2015-12-18T11:00:04.883 に答える