Spe*_*efy 3 image uibutton uitableview didselectrowatindexpath ios
我的桌面视图中有一个按钮,在点击后会发生变化.
在我的cellforrowatindexpath中,我有
[cell.graphicButton addTarget:self action:@selector(changeGraphic:)forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)
应该调用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];
Run Code Online (Sandbox Code Playgroud)
}
当我在changeGraphic方法中记录东西时,它返回正常.我是否正确更新了UIButton的图像?
它应该是
[cell.vicinitimeGraphicButton setImage:[UIImage imageNamed:@"travelDistanceGraphicGreen.png"] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
代替
[cell.vicinitimeGraphicButton setBackgroundImage:[UIImage imageNamed:@"travelDistanceGraphicGreen.png"] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
在我的情况下,图像被创建为背景
归档时间: |
|
查看次数: |
1007 次 |
最近记录: |