2009年01月25日

iPhone SDK Sample:Accessory

UITableViewでアクセサリービューの使い方。


UITableViewCell *theCell;
theCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UIImage *theImage = [UIImageView imageNamed:@"image.png"];
UIImageView *theView = [[UIImageView alloc] initWithImage:theImage];
theCell.accessoryView = theView;
[theView release];


のように使う。UIImageView imageNamed:はあまり使うべきではないが、ここでは同じイメージを使い回すことを前提にして使っている。

サンプルではNSButtonをアクセサリービューとしてつけているので、そのアクションの設定の仕方も参考になる。

マウスクリック位置から選択されたテーブルの行を判定する方法:

NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];


テーブル行が選択されたときの行反転の色を変える方法:

cell.selectionStyle = UITableViewCellSelectionStyleGray;


選択種類には以下がある。

UITableViewCellSelectionStyleNone,
UITableViewCellSelectionStyleBlue,
UITableViewCellSelectionStyleGray


選択をしたときの表示の変更をアニメーションにすることもできる。

アクセサリービューを独自ビューにするつ以外に既定のもの(チェックマーク、詳細ありボタンにするなどができます。

UITableViewCellAccessoryNone,
UITableViewCellAccessoryDisclosureIndicator,
UITableViewCellAccessoryDetailDisclosureButton,
UITableViewCellAccessoryCheckmark

posted by 永遠製作所 at 01:17| 東京 ☁| Comment(0) | TrackBack(0) | iPhone/iPod touch | このブログの読者になる | 更新情報をチェックする
この記事へのコメント
コメントを書く
お名前:

メールアドレス:

ホームページアドレス:

コメント: [必須入力]

※ブログオーナーが承認したコメントのみ表示されます。

この記事へのトラックバック
×

この広告は90日以上新しい記事の投稿がないブログに表示されております。