Ios 单击其他按钮时更改UIButton的图像

Ios 单击其他按钮时更改UIButton的图像,ios,uitableview,uibutton,Ios,Uitableview,Uibutton,在你潜水之前。。。 默认情况下,使用图像集将ControlState设置为Normal 当用户单击某个按钮时,它会更改按钮的图像,因为我将该按钮的目标设置为与所需的方法相对应。调用-(void)RadioButtonClicked:时,我需要更改所有其他RadioButton的图像 -(void)RadioButtonACLicked:{ //code to change radioButton A, the code i have works // Code to change all ot

在你潜水之前。。。 默认情况下,使用图像集将ControlState设置为Normal

当用户单击某个按钮时,它会更改按钮的图像,因为我将该按钮的目标设置为与所需的方法相对应。调用-(void)RadioButtonClicked:时,我需要更改所有其他RadioButton的图像

-(void)RadioButtonACLicked:{
//code to change radioButton A, the code i have works 
// Code to change all other buttons does not work. 
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ .... //配置单元格

....
//-------------Creation of Custom Buttons-------------// 
//----RadioButtonA----//
....
[radioButtonA addTarget:self action:@selector(radioButtonAClicked:)forControlEvents:UIControlEventTouchUpInside];

 [radioButtonA setImage:img2 forState:UIControlStateNormal];
钮扣创作

radioButtonB = [UIButton buttonWithType:UIButtonTypeCustom];

[radioButtonB addTarget:self action:@selector(radioButtonBClicked:)forControlEvents:UIControlEventTouchUpInside];
[radioButtonB setImage:img2 forState:UIControlStateNormal]; 
因此,当单击单选按钮时,我需要将所有其他按钮图像设置为相反

//When creating the button, set their tags
radioButtonA = [UIButton buttonWithType:UIButtonTypeCustom];
//Add this line
radioButtonA.tag = 111;

radioButtonB = [UIButton buttonWithType:UIButtonTypeCustom];
//Add this line
radioButtonB.tag = 112;
现在在

-(void)RadioButtonACLicked:{
   //code to change radioButton A, the code i have works 
   //Code to change all other buttons does not work. 
   radioButtonA = [self.view viewWithTag:111];
   radioButtonB = [self.view viewWithTag:112];
   //Change the images for radioButton A and B as you wish
}
执行以下操作

//When creating the button, set their tags
radioButtonA = [UIButton buttonWithType:UIButtonTypeCustom];
//Add this line
radioButtonA.tag = 111;

radioButtonB = [UIButton buttonWithType:UIButtonTypeCustom];
//Add this line
radioButtonB.tag = 112;
现在在

-(void)RadioButtonACLicked:{
   //code to change radioButton A, the code i have works 
   //Code to change all other buttons does not work. 
   radioButtonA = [self.view viewWithTag:111];
   radioButtonB = [self.view viewWithTag:112];
   //Change the images for radioButton A and B as you wish
}

我花了一段时间才开始工作

(void)radioButtonClicked:(UIButton *)sender
{
...

// Sets the UIImage for the custom RadioButtons. 
//img refers to radioOn and img2 refers to radioOff.
// uses an if esle conditional block inorder to correctly change the Images if teh conditions are met.

for(int i=0;i<[self.radioButtons count];i++){
    if ([[self.radioButtons objectAtIndex:i]tag] == sender.tag) {
    [[self.radioButtons objectAtIndex:i] setImage:img2 forState:UIControlStateNormal];

}

[sender setImage:img forState:UIControlStateNormal];

}
(无效)RadioButton选中:(UIButton*)发送方
{
...
//设置自定义单选按钮的UIImage。
//img指无线电接通,img2指无线电断开。
//使用if esle条件块,以便在满足条件时正确更改图像。

对于(inti=0;我花了一段时间才让它工作起来

(void)radioButtonClicked:(UIButton *)sender
{
...

// Sets the UIImage for the custom RadioButtons. 
//img refers to radioOn and img2 refers to radioOff.
// uses an if esle conditional block inorder to correctly change the Images if teh conditions are met.

for(int i=0;i<[self.radioButtons count];i++){
    if ([[self.radioButtons objectAtIndex:i]tag] == sender.tag) {
    [[self.radioButtons objectAtIndex:i] setImage:img2 forState:UIControlStateNormal];

}

[sender setImage:img forState:UIControlStateNormal];

}
(无效)RadioButton选中:(UIButton*)发送方
{
...
//设置自定义单选按钮的UIImage。
//img指无线电接通,img2指无线电断开。
//使用if esle条件块,以便在满足条件时正确更改图像。
对于(int i=0;i