2012-01-25 4 views
0

私はipadの開発では新しいですが、私はボタンをuitableviewcellに追加したいが、それは表示されません。このボタンをテーブルビューのセルに追加する方法。私はcellforRowAtIndexPathでこのコードを書いています私のコードは次のとおりです。事前にipadのuitableviewcellのボタンを追加する方法

UIButton *cellImgButton = [[UIButton alloc]initWithFrame:CGRectMake(300, 350, 40, 40)]; 
cellImgButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
UIImage *buttonImage = [UIImage imageNamed:@"remove.png"]; 
[cellImgButton setBackgroundImage:buttonImage forState:UIControlStateNormal]; 
[cellImgButton addTarget:self action:@selector(cellImgButton:) forControlEvents:UIControlEventTouchUpInside]; 
[cell.contentView addSubview:cellImgButton]; 

ありがとう:

答えて

0

インターフェイスビルダでプロトタイプセルを作成して、セルにUIButtonをドラッグするだけです。その後、新しいUITableViewCellクラスを作成し、ボタンをリンクします。

は、問題があなたのボタンの枠内にあるセルに

0

1)チェック表のセルの高さ

2)ボタンのフレームサイズを確認してください(手段のxとy axies)

1

を識別子を追加することを忘れないでください。試してみてください:

UIButton *cellImgButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[cellImgButton setFrame:CGRectMake(0, 5, 40 , 40) ]; 

UIImage *buttonImage = [UIImage imageNamed:@"remove.png"]; 
[cellImgButton setBackgroundImage:buttonImage forState:UIControlStateNormal]; 
[cellImgButton addTarget:self action:@selector(cellImgButton:) forControlEvents:UIControlEventTouchUpInside]; 

[cell.contentView addSubview:cellImgButton]; 
1

このコードを試してみてください。あなたは 'Y軸'が350であると言いました。行の高さを確認してください。そして、あなたの行の高さに関連する 'Y'軸を与えます。

UIButton *cellImgButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[cellImgButton setFrame:CGRectMake(10, 5, 40 , 40) ]; 
[cellImgButton setBackgroundImage:[UIImage imageNamed:@"remove.png"] forState:UIControlStateNormal]; 
[cellImgButton addTarget:self action:@selector(cellImgButton:) forControlEvents:UIControlEventTouchUpInside]; 
[cell.contentView addSubview:cellImgButton]; 
関連する問題