我的应用程序快完成了,但我遇到了问题,我无法从我制作的 阵列中删除对象。iphone-无法删除阵列中的对象
这是我的代码的示例:
-(void) TheGame{
squares = [[NSMutableArray arrayWithObjects: @"a", @"b", @"c", @"d", @"e", @"f", @"g", @"h" ,@"i" ,@"j", @"k", @"l", @"m", @"n", @"o", @"p", @"q", @"r", @"s", @"t", @"aa", @"bb", @"cc",@"dd", @"ee", @"ff", @"gg", @"hh", @"ii", @"jj", @"kk", @"ll", @"mm", @"nn", @"oo", @"pp", @"qq",@"rr", @"ss", @"tt", nil] retain];
s=40;
turn=1;
while(s >= 1)
if (turn == 1){
//Check for players move
//Here I added some if statement, and for every one I added
//[squares removeObject: @"b"]; X can be any object of the array.
turn = 0;
s = s - 1;
}
if (turn == 0){
//Here the computer should find an object from the array randomly. I used
//randomN = [squares objectAtIndex:arc4random() % [squares count]];
//to choose the random object.
//After choosing, the item should be removed from the array, also using
//[squares removeObject: @"X"]; X can be any object of the array.
turn = 1;
s = s - 1;
}
}
的问题是,例如,如果玩家从阵列选择了对象“B”,然后
[squares removeObject: @"b"];
应触发。
当涉及到计算机的随机移动时,它有可能会选择已经从数组中删除的相同对象 ,在我的示例中,它是@“b”。
因此,这意味着,该项目未从阵列时
[squares removeObject: @"X"];
触发器除去。
任何人都得到了这个问题的解决方案?
请,我需要你的帮助。
=======解决========
我试图用你的答案,但无法管理要解决的问题..
的解决方案是如此简单:只需将数组移动到“viewDidLoad”方法即可。
谢谢你们的帮助,很抱歉,但我不能接受答案,因为没有为我工作。 我很感谢你的努力。
你成为会员有3个月,并要求7个问题。你的其他6个问题都已经收到答案,其中一个甚至已经得到4个答案。我认为你应该考虑阅读常见问题 - http://stackoverflow.com/faq - 并接受你之前提出的问题的一些答案。一旦你这样做了,人们会更愿意帮助你。 – Jasarien 2011-03-20 20:17:07
嗨,但是当我尝试评价答案时,我收到一条消息,说我必须得到15个代表才能评分。 – 3madi 2011-03-20 20:31:06
我很抱歉,不知道,我刚刚做到了。接受了有用的答案我从用户 – 3madi 2011-03-20 20:37:20