gpt4 book ai didi

ios - 枚举按钮的 NSMutableArray 添加一些到另一个 NSMutableArray

转载 作者:行者123 更新时间:2023-11-28 20:08:40 27 4
gpt4 key购买 nike

这看起来很简单,但我只是得到一个空数组。

我想获取一个按下的按钮,找到它旁边的所有按钮(参见代码中的注释),并将所有找到的按钮添加到另一个 NSMutableArray。

然后我想遍历该数组并对每个按钮执行一些操作。

在下面,我使用 [caualtiesArray addObject: btn]; 将找到的按钮存储在数组中,但它似乎并没有这样做,我也不知道为什么。

-(void)detonateBomb:(UIButton*)bombDetonated{
//stop the spiketimers first
[spikeTimer invalidate];
[removeSpikeTimer invalidate];
//move bomb button (non enabled and hidden) over the pressed button
//really we are just going to use its rect to find buttons next
//to the bomb since its rect is lage enough to overlap the others
bombRadius.center=bombDetonated.center;
//create an array to hold any matches
//we cant use the original arrary
//because the array would be mutated while
//its being enumerated
NSMutableArray *caualtiesArray;
//I did try moving this to declare caualtiesArray
//in the .h....which didnt fix the issue
//loop through all of the unpopped buttons
//if any intersect with "bombRadius" they are next to the bomb
//add them to the array
for(UIButton *btn in mutableBubbleArray){
if (CGRectIntersectsRect(btn.frame, bombRadius.frame)) {
[caualtiesArray addObject: btn];
//^^This seems to be the problem
NSLog(@"------- added button: %ld", (long)[btn tag]);
NSLog(@"------- foundButtons: %ld", (long)[caualtiesArray count]);
NSLog(@"*******");
}
}
//now that we have them all
//pop them and add an extra 50 pts each
//lets see how many we have first though
NSLog(@"------- foundButtons: %ld", (long)[caualtiesArray count]);
for(UIButton *foundBtn in caualtiesArray){
score+=50;
[self popBubble:foundBtn];
NSLog(@"------- popping button: %ld", (long)[foundBtn tag]);
NSLog(@"*******--------------------");
}
//add an extra 100 pts
score+=100;
//move the bomb back off-screen
bombRadius.center=CGPointMake(-100, -100);
//clean the array
[caualtiesArray removeAllObjects];
}

这是我在控制台中得到的:

2014-01-15 00:25:39.331 TestApp[7324:60b] ------- (pop method)POPPED A BOMB
2014-01-15 00:25:39.333 TestApp[7324:60b] *********************************
2014-01-15 00:25:39.335 TestApp[7324:60b] ------- added button: 28
2014-01-15 00:25:39.337 TestApp[7324:60b] ------- foundButtons: 0
2014-01-15 00:25:39.339 TestApp[7324:60b] *******
2014-01-15 00:25:39.341 TestApp[7324:60b] ------- added button: 29
2014-01-15 00:25:39.342 TestApp[7324:60b] ------- foundButtons: 0
2014-01-15 00:25:39.345 TestApp[7324:60b] *******
2014-01-15 00:25:39.347 TestApp[7324:60b] ------- added button: 39
2014-01-15 00:25:39.350 TestApp[7324:60b] ------- foundButtons: 0
2014-01-15 00:25:39.352 TestApp[7324:60b] *******
2014-01-15 00:25:39.354 TestApp[7324:60b] ------- added button: 40
2014-01-15 00:25:39.355 TestApp[7324:60b] ------- foundButtons: 0
2014-01-15 00:25:39.357 TestApp[7324:60b] *******
2014-01-15 00:25:39.358 TestApp[7324:60b] ------- added button: 41
2014-01-15 00:25:39.360 TestApp[7324:60b] ------- foundButtons: 0
2014-01-15 00:25:39.361 TestApp[7324:60b] *******
2014-01-15 00:25:39.363 TestApp[7324:60b] ------- added button: 52
2014-01-15 00:25:39.364 TestApp[7324:60b] ------- foundButtons: 0
2014-01-15 00:25:39.366 TestApp[7324:60b] *******
2014-01-15 00:25:39.367 TestApp[7324:60b] ------- added button: 53
2014-01-15 00:25:39.368 TestApp[7324:60b] ------- foundButtons: 0
2014-01-15 00:25:39.370 TestApp[7324:60b] *******
2014-01-15 00:25:39.371 TestApp[7324:60b] ------- foundButtons: 0

显然,找到按钮工作正常,但它们没有被添加到新数组> 我只是不明白为什么。这似乎应该有效。

最佳答案

似乎您没有初始化 caualtiesArray。

caualtiesArray = [NSMutableArray 数组];

关于ios - 枚举按钮的 NSMutableArray 添加一些到另一个 NSMutableArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21130540/

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