Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在每个单元格前面的UITableView中显示新图像而不是另一个图像按钮_Iphone_Objective C_Xcode_Uitableview_Uibutton - Fatal编程技术网

Iphone 在每个单元格前面的UITableView中显示新图像而不是另一个图像按钮

Iphone 在每个单元格前面的UITableView中显示新图像而不是另一个图像按钮,iphone,objective-c,xcode,uitableview,uibutton,Iphone,Objective C,Xcode,Uitableview,Uibutton,我希望在单击表视图控制器中的另一个图像按钮后,立即将该按钮添加到该按钮的顶部。我在.h文件中有UIButton*按钮 CellForRow:{ button=[[UIButton alloc]initWithFrame:CGRectMake(230,0,40,40); [button addTarget:self action:@selector(buttonPressed:withEvent:) forControlEvents:UICo

我希望在单击表视图控制器中的另一个图像按钮后,立即将该按钮添加到该按钮的顶部。我在.h文件中有UIButton*按钮

    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];
}

这样做的目的是在第一个图像的顶部显示第二个图像。但是我想要的是让新图像取代旧图像。

它可以工作……但需要双击以更改图像。然后在后续单击时再次更改前一个图像
-(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];

                }

}