Iphone IF语句比较

Iphone IF语句比较,iphone,ios,xcode,Iphone,Ios,Xcode,在我的IF语句中,这有点奇怪,因为每次我的代码在其中循环时,只有SLOT1被调用并显示在我的调试器中,为什么?我的陈述有问题吗?谢谢 choiceSlot1 = TRUE; choiceSlot2 = TRUE; choiceSlot3 = TRUE; choiceSlot4 = TRUE; if (slot1 != [(UIImageView*)[self.carousel1 currentItemView] tag] || twoSlot1 !

在我的IF语句中,这有点奇怪,因为每次我的代码在其中循环时,只有SLOT1被调用并显示在我的调试器中,为什么?我的陈述有问题吗?谢谢

    choiceSlot1 = TRUE;
    choiceSlot2 = TRUE;
    choiceSlot3 = TRUE;
    choiceSlot4 = TRUE;   

    if (slot1 != [(UIImageView*)[self.carousel1 currentItemView] tag] || twoSlot1 != [(UIImageView*)[self.carousel2 currentItemView] tag] || choiceSlot1 ) {

        NSLog(@"Slot1");
        choiceSlot1 = FALSE;

    } 
    else if (slot2 != [(UIImageView*)[self.carousel1 currentItemView] tag] || twoSlot2 != [(UIImageView*)[self.carousel2 currentItemView] tag] || choiceSlot2) {

        NSLog(@"Slot2");
        choiceSlot2 = FALSE;


    }
    else if (slot3 != [carousel1 indexOfItemViewOrSubview:carousel1.superview] || twoSlot3 != [(UIImageView*)[self.carousel2 currentItemView] tag] || choiceSlot3) {

        NSLog(@"Slot3");
        choiceSlot3 = FALSE;


    }
    else if (slot4 != [(UIImageView*)[self.carousel1 currentItemView] tag] || twoSlot4 != [(UIImageView*)[self.carousel2 currentItemView] tag] || choiceSlot4) {

        NSLog(@"Slot4");
        choiceSlot4 = FALSE;

    }

因为只有当第一个
if
语句为
false
时,才会验证
else if

例如:

if (true) 
{
    // Will be executed
} 
else if (true) 
{
    // Will not be executed
}

if (false) 
{
    // Will not be executed
} 
else if (true) 
{
    // Will be executed
}
很简单

 if (slot1 != [(UIImageView*)[self.carousel1 currentItemView] tag] || twoSlot1 != [(UIImageView*)[self.carousel2 currentItemView] tag] || choiceSlot1 ) 
如果choiceSlot1为TRUE,则第一条语句始终为TRUE(使用OR,如果其中一个元素为TRUE,则为TRUE)


当第一个语句为true时,则不调用其余的else/if

你每次都把choiceSlot1设为真,因此它总是输入第一个if。
choiceSlot1
总是TRUE。。调用if语句的其余部分我应该怎么做?可能先尝试将choiceSlots设置为false,然后在进行更改时将其设置为TRUE?调用if语句的其余部分我应该怎么做?在调用之前删除
else
如果
。换言之,如果语句,则创建四个独立的
语句。是的,则所有语句都将被记录。