1

アプリケーションに2つのセクションを持つグループ化されたテーブルビューがあります。1つ目は1つの行で構成され、2つ目は5つで構成されます。このようにセルにボタンを追加しました。

   UIButton *newBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [newBtn setFrame:CGRectMake(5,10,35,30)];
    [newBtn setImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];
    [newBtn addTarget:self action:@selector(selector:)        forControlEvents:UIControlEventTouchUpInside];
    newBtn.tag=4;
    [cell.contentView addSubview:newBtn];

Now in that selector methode i need to change it with another image.I am trying to do that in this way

 UITableViewCell *cell=(UITableViewCell *)[sender superview];

    NSIndexPath *path=[self.mtableview indexPathForCell:cell];

「でも、ある時点でボトルネックになっています。誰かが私を正しい方向に向けることができますか?

4

2 に答える 2

3

ボタンだけの画像を変更したい場合は、セレクターに追加してください。

- (void)selector:(id)sender {
  //some code
  UIButton *button = (UIButton *)sender;
  [button setImage:[UIImage imageNamed:@"newicon.png"] forState:UIControlStateNormal];
  //some code
}
于 2012-10-31T06:36:09.020 に答える
2

このようにボタンのアクションメソッドを書く必要があります

-(void)cellBtnAction:(id)sender {

    UIButton *btn=(UIButton *)sender;
    //Write code for change image to button
    [btn setImage:imgObj forState:UIControlStateNormal];
}

これを試してみてくださいそれがあなたに役立つことを願っています

于 2012-10-31T06:37:29.237 に答える