2009-06-12 18 views
1

UITableViewCellを一時的にハイライトして、含まれているデータが変更されたことに注意を喚起したいと思います。UITableViewCellをハイライトするにはどうすればいいですか?

UITableViewCellメソッドがあります:-setHighlighted:(BOOL)animated:(BOOL)でも何もできません。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell; 
    switch (indexPath.section) { 
    case 0: { 
    if (indexPath.row == 0) { 
    cell = [[UITableViewCell alloc ] initWithStyle:UITableViewCellStyleDefault 
            reuseIdentifier:@"currentLoc"]; 
    cell.accessoryType = UITableViewCellAccessoryNone; 
     cell.textLabel.text = @"This is the special cell"; 
    } 
    [cell setHighlighted:YES animated:YES]; 
    [cell setHighlighted:NO animated:YES]; 

    //[cell setNeedsDisplay]; 

    } else { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
            reuseIdentifier:@"setLocAutomatically"]; 
    cell.accessoryType = UITableViewCellAccessoryNone; 
    cell.textLabel.text = @"Foo"; 

    } 
} break; 
case 1: { 
    cell = [[UITableViewCell alloc ] initWithStyle:UITableViewCellStyleDefault 
           reuseIdentifier:@"selectCity"]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    if (indexPath.row == 0) { 
    cell.textLabel.text = @"Select a Bar"; 
    } else { 
    cell.textLabel.text = @"Select a Baz"; 
    } 
} break; 
    } 
    [cell autorelease]; 
    return cell; 
} 

は私の試みのために上... [セルsetHighlight]を参照してください:

は、ここでビューコントローラの関連する部分です。

私の欲求不満は、セルが強調表示されていないため、動作させる方法がわからない。あなたはtableView:cellForRowAtIndexPath:でこのすべてをやっているので

カールC-M

答えて

4

、ありがとう、何もあなたがセルを返す後まで、画面のセルに起こりません。したがって、強調表示されるセルの設定は、ユーザーには何も表示されません。

あなたがしたいことは、メソッドから戻した後でセルをハイライト表示に設定する方法です。おそらくNSObject's performSelector:withObject:afterDelay:メソッドを調べてみるとよいでしょう - 遅延で強調表示されたセルを設定すると返され、表示されます。次にが強調表示されます。

0

セルのUILabelを変更し、セル自体を変更しようとするのではなく、単に外観を変更することを考えましたか?別のテキストの色や太字の可能性がありますか?あなたはtableView:cellForRowAtIndexPath:

以内に変更を保持できるようになる

はこれもハイライトのデフォルトの外観が変更された情報のあなたの追加メッセージと混合しないようにしています。強調表示は多くのことを意味しますが、テキストフォーマットを使用して特定の概念を示すことができます。

UILabel * textLabel = [yourCell textLabel]; 
// From here you can alter the text 

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UILabel_Class/Reference/UILabel.html

0

[tblView selectRowAtIndexPath:myIndex animated:YES scrollPosition:UITableViewScrollPositionTop]; 機能を使用してみてください。

16

だけでどんなコード/変更ハイライト/バックグラウンドを置く:私は私を切り株を続けているこの上のバリエーションを持っている

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
+4

テーブルビューにreloadDataを呼び出します受け入れられた答え、イモ。 –

+0

も私のために働いた – z22

0

。テーブルを使用して選択肢を示すウィザードがあります。選択が行われたら、選択した行を一時的にハイライトしてから、ウィザードの次のフレームに進みます。

私は

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

に進歩を行うしかし、私はハイライトが実現することはできません。

提案がありますか?

+0

私は、performSelector:withObject:afterDelay:のTimの提案にバリエーションを使用してしまった。私はセルを強調表示し、少し遅れてウィザードの次のフレームに進みます。それは私が必要なすべての選択を表示するだけで十分です。 –

0

このお試しください:

[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 
0
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
     if (//tell if cell is marked) { 
      [cell setBackgroundColor:[UIColor colorWithRed:158.0/255.0 green:28.0/255.0 blue:36.0/255.0 alpha:1.0]]; 
      [[cell textLabel] setTextColor:[UIColor whiteColor]]; 
      if ([cell detailTextLabel]) { 
        [[cell detailTextLabel] setTextColor:[UIColor whiteColor]]; 
      } 
     } 
     else 
     { 
      [cell setBackgroundColor:[UIColor whiteColor]]; 
      [[cell textLabel] setTextColor:[UIColor blackColor]]; 
      if ([cell detailTextLabel]) { 
        [[cell detailTextLabel] setTextColor:[UIColor blackColor]]; 
      } 
     } 
} 

uitableviewdelegateでの使用にこれをして、電池マークにセルを強調表示したいときに、これは私のために働いたとあるべき

関連する問題