0

の中にボタンを作成しました。ボタンUITableViewCellをクリックすると、インデックス値を使用してビューコントロールの作成者に移動します。

 tapped  = [UIButton buttonWithType:UIButtonTypeCustom];

[tapped setFrame:CGRectMake(0, 0, 320, 100)];
[tapped setTitle:@"button" forState:UIControlStateNormal];

NSInteger tet;

tet = indexPath.row; 
[tapped addTarget:self action:@selector(tapped:) forControlEvents: UIControlEventTouchDown];

[Cell addSubview:tapped];
4

3 に答える 3

1

ボタンにindexPath.rowのタグを付ける必要があります。

tapped.tag = indexPath.row;

イベント処理コード内で、そのタグを使用してインデックスを検索する必要があります。

-(void) tapped:(UIButton *)sender
{
    UIButton *btn = (UIButton *)sender;
    int index = btn.tag;
    //Do rest...
}
于 2012-06-22T11:55:26.287 に答える
0

次のようにボタンにタグを付けることができます:

tapped.tag = indexPath.row

そしてタップされた方法では、次のように使用できます。

-(IBAction)tapped:(id)sender
{
 UIButton *btn = (UIButton *)sender;
int index = btn.tag;

}

要件に応じてこのインデックスを使用してください...

于 2012-06-22T12:00:44.897 に答える
0

これを試して

-(void) tapped:(UIButton *)sender
{
    UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview];
    NSIndexPath *indexPath = [myTableView indexPathForCell:clickedCell];
    int section = indexPath.section;
    // You get easily your index path row
    int row = indexPath.row;
    // push your controller 

}

最初にコードを更新する

イベントを使うUIControlEventTouchUpInside

tapped  = [UIButton buttonWithType:UIButtonTypeCustom];

[tapped setFrame:CGRectMake(0, 0, 320, 100)];
[tapped setTitle:@"button" forState:UIControlStateNormal];

NSInteger tet;

tet = indexPath.row; 
[tapped addTarget:self action:@selector(tapped:) forControlEvents: UIControlEventTouchUpInside];

[Cell addSubview:tapped];
于 2012-06-22T11:59:34.350 に答える