ios - Sprite Kit - 基于 NSMutableArray 对象列表删除 SKNode
<p><p>我在删除名称/ID 在我的 NSMutableArray 中的所有节点时遇到了一些麻烦。
我已将每个对象的值设置为唯一名称。所以我只能删除 NSMutableArray 中的那些。</p>
<p>对象在循环中创建,每个对象的名称都是唯一的。</p>
<p>像这样:</p>
<pre><code> myObject.name = @"8dAN3kgh6E";
</code></pre>
<p>下一个循环</p>
<pre><code> myObject.name = @"WsFkdGrmHm";
</code></pre>
<p>下一个循环</p>
<pre><code> myObject.name = @"ov5BjzHGiw";
</code></pre>
<p>然后将这些值相加并存储在一个数组中。</p>
<p>NSMutableArray *currentShapeArray </p>
<pre><code>(
8dAN3kgh6E,
WsFkdGrmHm,
ov5BjzHGiw
)
</code></pre>
<p>然后我循环遍历 currentShapeArray,我就是这样做的:</p>
<pre><code>for (NSString *myObjectNames in currentShapeArray) {
NSLog(@"%@", myObjectNames); //works and gives each value correctly
}
</code></pre>
<p>但是对于我的生活,我似乎无法弄清楚如何在这一点上删除包含该特定 node.name 的对象。 </p>
<p>类似于 ; ...但我需要根据 myObject.name 属性进行选择。</p>
<p>我确信这很简单,希望有人可以帮助我朝正确的方向前进。谢谢!</p>
<p><strong>更新:1.</strong></p>
<p>我尝试了 sangony 的建议,由于某种原因,当我使用它时它给了我以下错误。</p>
<pre><code>2014-05-07 23:11:56.163 dotmatcher NODE NAME: FY7opRB1Wk
2014-05-07 23:11:56.164 dotmatcher ButtonTmp 1
2014-05-07 23:11:56.164 dotmatcher Previous 1
2014-05-07 23:11:56.164 dotmatcher -: unrecognized selector sent to instance 0xee1fe50
2014-05-07 23:11:56.167 dotmatcher *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-: unrecognized selector sent to instance 0xee1fe50'
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
UITouch* touch = ;
CGPoint loc = ;
NSArray *nodes = ;
for (SKNode *node in nodes) {
NSString *tmp = node.name;
if (tmp.length !=0) {
NSLog(@"ended");
NSString *buttonTmp = ;
if ( && ) {
endButton = @"1";
NSLog(@"NODE NAME: %@",node.name);
NSLog(@"ButtonTmp %@", buttonTmp);
NSLog(@"Previous %@", previousButton);
NSMutableArray *discardedItems = ;
for(SKNode *object in currentShapeArray)
{
if()
{
; // not sure if you need this or not
;
}
}
;
NSLog(@"ButtonID: %@",);
NSLog(@"ButtonType: %@",);
NSLog(@"ButtonColumn: %@",);
NSLog(@"ButtonRow: %@",);
NSLog(@"AFTER REMOVE%@",currentShapeArray);
}
}
}
}
}
</code></pre>
<p><strong>UPDATE 2</strong> 这是让它工作的最终代码。谢谢桑尼!</p>
<pre><code>NSMutableArray *discardedItems = ;
for(SKNode *object in currentShapeArray)
{
;
;
}
;
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>可能是这样的:</p>
<pre><code>NSMutableArray *discardedItems = ;
for(SKNode *object in currentShapeArray)
{
if()
{
; // not sure if you need this or not
;
}
}
;
</code></pre></p>
<p style="font-size: 20px;">关于ios - Sprite Kit - 基于 NSMutableArray 对象列表删除 SKNode,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23525180/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23525180/
</a>
</p>
页:
[1]