Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 比较两个标记的对象?_Iphone_Objective C_Ios_Xcode_If Statement - Fatal编程技术网

Iphone 比较两个标记的对象?

Iphone 比较两个标记的对象?,iphone,objective-c,ios,xcode,if-statement,Iphone,Objective C,Ios,Xcode,If Statement,我有两个按钮,每个都有标签。我如何比较它们,每个都有自己的标签和图像。例如: // sender is (UIButton *)sender. if ((sender.tag == 1)theImageOnTheButton == (sender.tag == 2)theImageOnTheButton { // egual } else // not egual 因此,如果发送者标记为1,那么他的图像等于标记为2的发送者,他的图像等于,比如说等于,否则,就说它们不是相等的。

我有两个按钮,每个都有标签。我如何比较它们,每个都有自己的标签和图像。例如:

// sender is (UIButton *)sender.

if ((sender.tag == 1)theImageOnTheButton == (sender.tag == 2)theImageOnTheButton
{
    // egual
}
else
    // not egual
因此,如果发送者标记为1,那么他的图像等于标记为2的发送者,他的图像等于,比如说等于,否则,就说它们不是相等的。我该怎么做

原代码为:

-(void)flipView:(UIButton*)sender
{    
    x = x + 1;
    if (x == 1)
    {
        //  When flipping the first card
        NSLog(@"X == 1");
        [sender setTag:1];
    }
    else if (x == 2)
    {
        //  When flipping the second card
        NSLog(@"X == 2");
        x = 0;
        [sender setTag:2];

        if ((sender.tag == 2) == (sender.tag == 1))
        {
            NSLog(@"IGUAL");
        }
        else
        {
            NSLog(@"NOT EGUAL");
        }
    }
}

谢谢分配。

如果我有两个以上的按钮,那么如何比较图像

假设您有两个带标签的按钮

IBOutlet UIButton *btn1, *btn2;

btn1.tag = 1;
btn2.tag = 2;
将这两个IBOutlet按钮连接到xid文件中的按钮,并为这两个按钮添加一个公共IBAction

 -(IBAction)checkingBtns:(id)sender
  {

  if([sender tag] == 1){
      //Do what ever with your btn1 change color, change text, change image
    }

   if([sender tag] == 2){
      //Do what ever with your btn2 change color, change text, change image
    }

   }
希望这对你有帮助!!正确连接管道和操作,以实现正常功能

[sender setTag:2];
然后-

if ((sender.tag == 2) == (sender.tag == 1))

当“已标记”设置为2时,它如何可以等于1?逻辑错误。

我认为你需要重新表述你的问题,因为它目前毫无意义。您发布的代码是可读/有效的语法。