Copyright (C) iPhoneアプリ開発備忘録 All rights reserved.
ブログ内で記したコード、内容の正確性は保証いたしません。
記載内容を実装したことにより発生した不具合・損害等の責任は一切負いません。



2009年11月27日

TableViewCellの中にUIButtonを作る



TableViewCellの中にUIButtonを作る方法。

HogeViewController.h
@interface HogeViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
IBOutlet UITableView* _itemTable;
UIButton *roundedButtonType;

}

@property (nonatomic, retain)IBOutlet UITableView *_itemTable;
@property (nonatomic, retain, readonly) UIButton *roundedButtonType;



HogeViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [self._itemTable dequeueReusableCellWithIdentifier:@"hogeCell"];
if (cell == nil) {
CGRect frame = CGRectMake(0, 0, 300, 44);
cell = [[[UITableViewCell alloc] initWithFrame:frame
reuseIdentifier:@"hogeCell"] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.font = [UIFont systemFontOfSize:14];
}

UIButton *button = [self roundedButtonType];
[cell.contentView addSubview:button];

}

- (UIButton *)roundedButtonType
{
if (roundedButtonType == nil)
{
// create a UIButton (UIButtonTypeRoundedRect)
roundedButtonType = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
roundedButtonType.frame = CGRectMake(198.0, 5.0, 97.0, 35.0);
[roundedButtonType setTitle:@"設定" forState:UIControlStateNormal];
roundedButtonType.backgroundColor = [UIColor clearColor];
[roundedButtonType addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];

roundedButtonType.tag = 1; // tag this view for later so we can remove it from recycled table cells
}
return roundedButtonType;
}


参考:Apple iPhone Dev Center提供サンプルソース/UICatalog


 

タグ:iPhone
posted by mobileDeveloper at 22:45 | Comment(0) | TrackBack(0) | UIButton はてなブックマーク - TableViewCellの中にUIButtonを作る | このブログの読者になる | 更新情報をチェックする
この記事へのコメント
コメントを書く
お名前:

メールアドレス:

ホームページアドレス:

コメント:

認証コード: [必須入力]


※画像の中の文字を半角で入力してください。
※ブログオーナーが承認したコメントのみ表示されます。

この記事へのトラックバック
Apple、Appleのロゴ、App Store、iPodのロゴ、iTunesは、米国および他国のApple Inc.の登録商標です。
iPhone、iPod touch、iPadはApple Inc.の商標です。
iPhone商標は、アイホン株式会社のライセンスに基づき使用されています。
その他、本ブログに記載されている製品名、会社名は、それぞれ各社の商標または登録商標です。