gpt4 book ai didi

ios - 如何在 iOS 的 NSArray 中获取未选择的数组

转载 作者:行者123 更新时间:2023-11-29 01:45:52 25 4
gpt4 key购买 nike

我正在 iOS 中使用 Objective-C 制作一款匹配游戏有一组 12 张卡片(3 列和 4 行),它是连接到 IBOutletCollectionUIButton 数组,问题是当你点击第一张卡片时,你也可以同时点击其他卡牌,但允许点击的卡牌必须只有2张。如果被点击的卡片大于 1 且小于 2,如何防止卡片被点击。

最佳答案

//One action for all buttons
-(void)buttonAction:(UIButton*)button
{

//if user select three button at a time, dont do further operations
if (previousButton && currentButton) {
return;
}

//previous button is the first button
if(previousButton==nil)
{
previousButton=button;
}
//current button is the second button
else if(currentButton==nil)
{
currentButton=button;
}
//if button is selected, set button as not selected and vice versa
if([button isSelected]==NO)
{
[button setSelected:YES];
}
else
{
[button setSelected:NO];
}
//if user press the same button again and again
if (currentButton==previousButton)
{
currentButton=nil;
if([previousButton isSelected]==NO)
{
previousButton=nil;
}
return;
}
else if((currentButton!=previousButton)&&(currentButton!=nil))
{
//both button tags are same, that means both selected state images are same
if(previousButton.tag==currentButton.tag)
{
[self performSelector:@selector(delay) withObject:nil afterDelay:0.5];
}
else
{
[self performSelector:@selector(delayTwo) withObject:nil afterDelay:0.5];
}
}
}

-(void)delay
{
//[currentButton setHidden:YES];
//[previousButton setHidden:YES];
currentButton=nil;
previousButton=nil;
score++;
NSLog(@"Score %d",score);
//the final stage, that means left only two buttons
if(score==6)
{
//[self endGame];
}
}

-(void)delayTwo
{
[currentButton setSelected:NO];
[previousButton setSelected:NO];
currentButton=nil;
previousButton=nil;
}

在 viewDidLoad 中,根据需要分配所有按钮选择和正常状态图像或标题

关于ios - 如何在 iOS 的 NSArray 中获取未选择的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31932863/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com