在您的代碼:
if ((total == (total1 && total2 && total3)))
{
[scrollview.contentOffset = CGPointMake (0,0)];
}
當if表達式,(total1 && total2 && total3)
首先評估。這可以是YES
或NO
(如果您願意,也可以是true或false)或(0或1)。
所以你的代碼等同於以下內容:
BOOL allVariablesAreNotZero = total1 && total2 && total3;
if (total == allVariablesAreNotZero)
{
[scrollview.contentOffset = CGPointMake (0,0)];
}
編輯問題被更好地解釋
後讓你的按鈕執行以下操作按下時:
- (void)buttonClicked:(id)sender
{
UIButton *button = (UIButton *)sender;
buttonsCombination = buttonsCombination | (1 << button.tag);
}
其中buttonsCombination
是一個NSUInteger。然後使用下面的測試,看看是否被按下的按鈕是正確的人(我有三個按鈕這樣做,但你猜的想法)
NSUInteger correctCombination = (1 << button1) | (1 << button2) | (1 << button3)
if (buttonsCombination == correctCombination) {
// The combination is correct
} else {
// The combination is incorrect
}
buttonsCombination = 0;
最後,請注意這個作品,因爲有足夠的位在一個NSUInteger中爲30個按鈕。這裏我用bitwise operators|
和<<
。
來源
2012-02-15 01:18:56
sch
您需要說明total,total1,total2和total3可能具有的值。 – 2012-02-15 01:07:42
你去了。希望它有助於找到我的問題的答案。 – SeongHo 2012-02-15 01:20:25
你有多少個按鈕?當用戶按下這些按鈕時會發生什麼,但是其他按鈕呢?當用戶按下其中一個按鈕兩次或更多次時會發生什麼? – sch 2012-02-15 01:44:35