2011-08-08 10 views
1

セルのテキストをクリックすると青色になり、再び同じセルに戻ると、別のセルをクリックするまで青色のままです。 UITableViewと詳細テキストラベルを使用しています。以下のように、ユーザーがUITableViewセルの色が消えない

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
    .. your view changing code 
} 

答えて

2

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

を追加します。

- (void)viewWillAppear:(BOOL)animated 
{ 
    // this UIViewController is about to re-appear, make sure we remove the current selection in our table view 
    NSIndexPath *tableSelection = [self.tableView indexPathForSelectedRow]; 
    [self.tableView deselectRowAtIndexPath:tableSelection animated:NO]; 
} 
5

は、デリゲートのdidSelectRowAtIndexPath:方法であなたの行の選択を解除します

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 

そして、あなたのクラスにこのコードを追加しますcellForRowAtIndex

+0

- (無効)にtableView:(のUITableView *)のtableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { \t \t CategoriesList * dvController = [[CategoriesList alloc] initWithNibName:@ "CategoriesList"バンドル:nil]; \t //選択したオブジェクトを新しいView Controllerに渡します。 \t //dvController.description = description; \t //dvController.title=title; \t //dvController.descriptionImage=descriptionImage; \t [self.navigationController pushViewController:dvController animated:YES]; \t [dvController release]; \t } – ali

+0

コードで編集していますが、機能していません – ali

+0

@ali "not working"は間違った説明です。何がうまくいかない? – Vladimir

0

ちょうど選択のスタイルを削除します:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
    UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cell1.png"]]; 
    [cell setBackgroundView:img]; 
    [img release]; 
} 
+0

私はこのように1つのコントローラで動作しますが、2番目のビューでは、そこに行くとclicl戻るボタンは、例外を与えるテーブルビューを移動する – ali

0

は、あなたがする必要がある行を選択したとき

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    ... 
} 
関連する問題