0

そのボタンがクリックされるとすぐに、テーブル ビュー コントローラーの別の画像ボタンの上に画像を追加したいと考えています。.h ファイルに UIButton *button があります。

    CellForRow:{
    button=[[UIButton alloc]initWithFrame:CGRectMake(230,0,40,40); 
   [button addTarget:self action:@selector(buttonPressed:withEvent:)                 forControlEvents:UIControlEventTouchUpInside]; 
[button setImage:[UIImage imageNamed:"a"] forState:UIControlStateNormal];
button.tag=indexPath.row;
[cell addSuBView:button];
[cell setIndentationWidth:1];
[cell setIndendationLevel:1];
}
-(void)buttonPressed:(id) sender withEvent: (UIEvent *) event{
UIButton *mybtn=(UIButton*) sender;
[mybtn setImage:[UIImage imageNamed:"b"] forState:UIControlStateNormal];
}

これが行うことは、最初の画像の上に 2 番目の画像を表示することです。しかし、私が望むのは、古いイメージの代わりに新しいイメージを取得することです。

4

1 に答える 1

0
-(void)buttonPressed:(id)sender withEvent:(UIEvent *)event{
UIButton *button = (UIButton *)sender;
button.selected = ! button.selected;

                if (button.selected) {
                    [button setBackgroundImage:[UIImage imageNamed:@"a.png"] forState:UIControlStateNormal];
                }
                else{
                    [button setBackgroundImage:[UIImage imageNamed:@"b.png"] forState:UIControlStateNormal];

                }

}
于 2012-09-28T14:03:38.840 に答える