2010年5月18日火曜日

UITableViewCell

UITableViewCellクラスは、UITableViewクラスのテーブルの書く行に設定されるクラスの属性や振る舞いを定義するクラス。このクラスには、セルの選択の管理やハイライトの状態、アクセサリとなるビュー、セルの背景やインデント処理等が含まれる。またテキストや画像のセルの内容を設定・管理するプロパティがある。
UILabel and UIImageView オブジェクトの属性(カラー、フォント、イメージ等)をセットできる。
標準でないスタイルを持たせる場合は、セル内容のビュー (contentView プロパティ) でサブビューを加えることができる。

UITableViewCell オブジェクトの生成

  • (id)initWithStyle:(UITabelViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  •    UITableViewCellStyleDefault テキストラベル(黒文字、左寄せ)付きの単純なセルスタイル。
  •    UITableViewCellStyleValue1 左に黒テキスト(左寄せ)ラベルがあり、右手に青テキスト(右寄せ)ラベルがあるセルスタイル。設定画面等に使われている。
  •    UITableViewCellStyleValue2 左に青テキスト(右寄せ)ラベルがあり、右手に黒テキスト(左寄せ)ラベルがあるセルスタイル。連絡先等に使われている。
  •    UITableViewCellStyleSubtitle 上部に渡り左寄せのラベルがあり、さらにその下に小さい左寄せのグレーテキストがあるセルスタイル

セルをリユースする


セル内のテキストを管理する

  •   UILabel *textLabel  property
  •        ex.      cell.textLabel.text = [listData objectAtIndex:row];
  •                   cell.textLabel.font =  [UIFont boldSystemFontOfSize: 25]; 
  •   UILabel *detailTextLabel  property
     以下はOS2.0以前用

セル内のイメージを管理する

  •   UIImageView *imageView  property

    •     ex.  UIImage *image = [UIImage imageNamed:@"star.png"];
    •           UIImage *image2 = [UIImage imageNamed:@"satr2.png"]
    •          cell.imageView.image = image;
    •           cell.imageView.highlightedImage = Image2;

    • 以下はOS2.0以前用
  •   UIImage *image  property
  •   UIImage *selectedImage  property

セルオブジェクトのビューにアクセスする

  •   UIView contentView  property
  •        Cellオブジェクトの表示オブジェクトを返す(読み取り専用)。
  ex1.
    CGRect nameLabelRect = CGRectMake(0, 5, 70, 15);
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:nameLabelRect];
    nameLabel.textAlignment = UITextAlignmentRight;
    nameLabel.text = @"Name:";
    nameLabel.font = [UIFont boldSystemFontOfSize:12];
    [cell.contentView addSubview: nameLabel];
    [nameLabel release];


  ex.2
    CGRect nameValueRect = CGRectMake(80, 5, 200, 15);
    UILabel *nameValue = [[UILabel alloc] initWithFrame: nameValueRect];
    nameValue.tag = kNameValueTag;
    [cell.contentView addSubview:nameValue];
    [nameValue release];
     .
     .
    NSUInteger row = [indexPath row];
    NSDictionary *rowData = [self.computers objectAtIndex:row];
    UILabel *name = (UILabel *)[cell.contentView viewWithTag:kNameValueTag];
    name.text = [rowData objectForKey:@"Name"];


アクセサリビューを管理する


セルの選択とハイライトを管理する


セルを編集する


状態遷移を変更する


コンテンツの字下げを管理する


ターゲットとアクションを管理する

These properties are deprecated as of iPhone OS 3.0. Instead, use the tableView:commitEditingStyle:forRowAtIndexPath: method of theUITableViewDataSource protocol or the tableView:accessoryButtonTappedForRowWithIndexPath: method of the UITableViewDelegate protocol.

0 件のコメント:

コメントを投稿