我有一个 iPhone 应用程序问题已经困扰了我好几天了,而且看起来真的不应该这么困难,所以我确定我遗漏了一些明显的东西。我已经研究了很多关于“类似”主题的论坛讨论,但没有具体解决这个问题。
需要明确的是,如果我应该研究一些文档或其他来源,请指出我正确的方向。
开始...
我有一个在表格(uitableview)中向用户显示的项目列表。每个项目的单元格(uitableviewcell)是自定义的,包含两个图像按钮(uibuttons:绿色和红色)。正如预期的那样,对于表格中的每个项目,用户都可以单击任何按钮。基于一个按钮的monitoringRequestType参数,该按钮调用一个单独的进程来更新服务器。如果状态为“已批准”,则图像分别变为“已批准”和“拒绝”。因此,当我单击红色按钮时,服务器将状态更新为“拒绝”,然后图像更改为“批准”和“已拒绝”。很简单,对吧?
所以,这里是问题:
单击拒绝按钮时,“批准”图像出现在“已批准”图像之上(因此可以看到两个图像),而“已拒绝”图像工作正常。为简洁起见,我只在此处包含相关代码(希望格式化适当地):
CellForRow:
if(indexPath.section==0){
NSDictionary *dict=[saveJson objectAtIndex:indexPath.row];
NSString* sMonitoringType = [dict valueForKey:@"monitoringType"];
UIButton *button1= [[UIButton alloc] initWithFrame:CGRectMake(230,10,40,40)];
UIButton *button2= [[UIButton alloc] initWithFrame:CGRectMake(280,10,40,40)];
if([sMonitoringType compare:@"Pending"] == NSOrderedSame){
[button1 setImage:[UIImage imageNamed:@"approve"]
forState:UIControlStateNormal];
[button1 addTarget:self
action:@selector(greenButtonPressed:withEvent:)
forControlEvents:UIControlEventTouchUpInside];
button1.tag= indexPath.row;
[button2 setImage:[UIImage imageNamed:@"reject"]
forState:UIControlStateNormal];
[button2 addTarget:self
action:@selector(redButtonPressed:withEvent:)
forControlEvents:UIControlEventTouchUpInside];
button2.tag= indexPath.row;
} else if([sMonitoringType compare:@"Approved"] == NSOrderedSame){
[button1 setImage:[UIImage imageNamed:@"alreadyapproved"]
forState:UIControlStateNormal];
[button2 setImage:[UIImage imageNamed:@"reject"]
forState:UIControlStateNormal];
[button2 addTarget:self
action:@selector(redButtonPressed:withEvent:)
forControlEvents:UIControlEventTouchUpInside];
button2.tag= indexPath.row;
} else if([sMonitoringType compare:@"Rejected"] == NSOrderedSame){
[button1 setImage:[UIImage imageNamed:@"approve"]
forState:UIControlStateNormal];
[button2 setImage:[UIImage imageNamed:@"alreadyrejected"]
forState:UIControlStateNormal];
[button1 addTarget:self
action:@selector(greenButtonPressed:withEvent:)
forControlEvents:UIControlEventTouchUpInside];
button1.tag= indexPath.row;
}
[cell addSubview:button1];
[cell addSubview:button2];
[button1 release];
[button2 release];
}
return cell;
}