0

UITableViewをロードしているときは、5つのセルが含まれることもあれば、4つのセルが含まれることもあります。セルの数に応じて、行2または行3のいずれかにAccessoryDe​​tailボタンを設定します。試してみたので条件が機能することはわかっていますdidSelectRowAtIndexPath:が、何らかの理由でTableViewが更新されていないようです。表示される行数によって異なります。でTableViewデータを正常にリロードしていますviewWillAppear:が、AccessoryDe​​tail[tableView reloadData]の問題は処理されません。私は[tableView reloadInputViews]無駄に使用しようとしました。問題は、AccessoryDe​​tail画像が、アプリケーションからロードを開始するビューに応じて、常に行2または行3のいずれかに設定されることです。

cellForRowAtIndexPath:メソッドのロジックは次のとおりです。

if ((row == 2) && ([[self.office boxAddress] length] == 0) || (row == 3) && ([[self.office boxAddress] length] != 0)) {
            cell.selectionStyle = UITableViewCellSelectionStyleGray;
            cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        }

編集:Simon Leeの提案に従って、else句を使用してメソッドを次のように変更しましたが、どちらも機能しないようです:

if (cell == nil) {

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:OfficeCellIdentifier] autorelease];


 if ((row == 2) && ([[self.office boxAddress] length] == 0) || (row == 3) && ([[self.office boxAddress] length] != 0)) {
     cell.selectionStyle = UITableViewCellSelectionStyleGray;
     cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
 //NSLog(@"row == 2 && [[self.office boxAddress] length] == 0 || row == 3");
 } else {
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
     cell.accessoryType = UITableViewCellAccessoryNone;
 }

}
4

2 に答える 2

1

選択スタイルとアクセサリ タイプをリセットする必要があります。else 句はありません...一度設定すると、それだけです。セルを再利用すると、アクセサリがリセットされることはありません....

于 2011-06-16T12:46:44.463 に答える
1

if-else ステートメントを if( cell == nil ) コード ブロックの外に置きます。セルを再利用している場合、コードは呼び出されません。

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:OfficeCellIdentifier] autorelease];
}

 if ((row == 2) && ([[self.office boxAddress] length] == 0) || (row == 3) && ([[self.office boxAddress] length] != 0)) {
     cell.selectionStyle = UITableViewCellSelectionStyleGray;
     cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
 } else {
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
     cell.accessoryType = UITableViewCellAccessoryNone;
 }
于 2011-06-16T14:03:52.893 に答える