我的while循環似乎不起作用。加載此視圖時,應用程序凍結。 當我刪除包含while循環的代碼部分時,應用程序不會凍結。雖然(不)循環凍結應用程序
我在尋找的是一段代碼,它會導致相同的數組不會被選擇兩次。
@interface ThirdViewController()
@end
@implementation ThirdViewController
...
NSString * Answer = @"";
NSArray * RAMArray;
...
- (void)NewQuestion
{
NSString * PlistString = [[NSBundle mainBundle] pathForResource:@"Questions" ofType:@"plist"];
NSMutableArray * PlistArray = [[NSMutableArray alloc]initWithContentsOfFile:PlistString];
NSArray *PlistRandom = [PlistArray objectAtIndex: random()%[PlistArray count]];
while (![PlistRandom isEqual: RAMArray])
{
NSArray *PlistRandom = [PlistArray objectAtIndex: random()%[PlistArray count]];
}
RAMArray = PlistRandom;
...
}
- (void)Check:(NSString*)Choise
{
...
if ([Choise isEqualToString: Answer])
{
...
[self NewQuestion];
}
}
- (IBAction)AnsButA:(id)sender
{
UIButton *ResultButton = (UIButton *)sender;
NSString *Click = ResultButton.currentTitle;
[self Check:Click];
}
這意味着循環是無限的 – 2013-05-08 15:43:30
又如何解決呢? – Berendschot 2013-05-08 15:44:28
通過找出是什麼使其無限 – 2013-05-08 15:46:43