我的表格视图中有一个按钮,它应该在被点击后改变。
在我的 cellforrowatindexpath 中,我有
[cell.graphicButton addTarget:self action:@selector(changeGraphic:)forControlEvents:UIControlEventTouchUpInside];
应该调用 changeGraphic (更改图形)。调用成功,但在 changeGraphic 中图像没有改变。
- (IBAction)changeGraphic:sender
{
buttonState++;
// button state is an int, im not using BOOl because I have more than 2 images to change from, but for this question i only included 2
if(buttonState == 2){
buttonState = 0;
}
// 1 = travel time 2 =activity time 3 = total time
if (buttonState == 0) {
[cell.vicinitimeGraphicButton setBackgroundImage:[UIImage imageNamed:@"travelDistanceGraphicGreen.png"] forState:UIControlStateNormal];
}
if (buttonState == 1) {
[cell.vicinitimeGraphicButton setBackgroundImage:[UIImage imageNamed:@"activityTimeGraphicGreen.png" ] forState:UIControlStateNormal];
}
[self.tableView beginUpdates];
[self.tableView reloadData];
[self.tableView endUpdates];
}
当我在 changeGraphic 方法中记录内容时,它返回正常。我是否正确更新了 UIButton 的图像?