Iphone 在每个单元格前面的UITableView中显示新图像而不是另一个图像按钮
我希望在单击表视图控制器中的另一个图像按钮后,立即将该按钮添加到该按钮的顶部。我在.h文件中有UIButton*按钮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
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];
}
}