按我的iOS应用程序中的按钮调用changeLanguage
方法。
- (void)changeLanguage:(BOOL) isMyanmar {
if (hasRun == YES) {
return;
}
hasRun = YES;
NSUserDefaults * userdefaults = [NSUserDefaults standardUserDefaults];
[userdefaults setBool:isMyanmar forKey:@"myanmar"];
[userdefaults synchronize];
[self updateCurrentLanguageText];
if ([self isMyanmar]) {
[self changeLanguageFlag:@"MyanmarFlagBig"];
} else {
[self changeLanguageFlag:@"UnitedKingdomFlagBig"];
}
[self countDown];
}
- (void)countDown {
static int i = 3;
if (i == 3) {
i--;
UIImage *three = [UIImage imageNamed:@"Three"];
countDownFlag = [[UIImageView alloc] initWithImage:three];
countDownFlag.frame = CGRectMake(0, 370, countDownFlag.frame.size.width, countDownFlag.frame.size.height);
countDownFlag.center = CGPointMake(width / 2, countDownFlag.center.y);
[self.view addSubview:countDownFlag];
[self performSelector:@selector(countDown) withObject:nil afterDelay:0.5];
} else if (i == 2) {
i--;
UIImage *two = [UIImage imageNamed:@"Two"];
[countDownFlag setImage:two];
[self performSelector:@selector(countDown) withObject:nil afterDelay:0.5];
} else if (i == 1) {
i--;
UIImage *one = [UIImage imageNamed:@"One"];
[countDownFlag setImage:one];
[self performSelector:@selector(countDown) withObject:nil afterDelay:0.5];
} else {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
用于运行良好但最近运行的方法在[self countDown]
处遇到线程问题。
可能导致问题的原因是什么?如何解决?
修改
如何调用changeLanguage
两种方法称为此方法:
- (void)changeLanguageToEnglish {
[self changeLanguage:false];
}
- (void)changeLanguageToMyanmar {
[self changeLanguage:true];
}
按钮如何调用方法:
[languageButton addTarget:self action:@selector(changeLanguageToEnglish) forControlEvents:UIControlEventTouchUpInside];