我是客观C的新手,我被困在我的身上。 我搜索了一些问题,但似乎没有人回答我的具体需求,希望你们能提供帮助! :)
我正在制作一个包含两个组件的选择器视图;一个与所有美国和一个与他们的首都。
现在当按下按钮时,我想要一个'if else语句'来检查两个数组的索引是否匹配,以及它是否确实创建了一个动作。 有人可以帮我解决开放状况吗?现在它给了我'预期表达'错误。
if (_stateList objectAtIndex:[]== _capitalList objectAtIndex[]) {
// Defining State & capitalnames by row
NSInteger stateRow = [self.picker selectedRowInComponent:StatesList];
NSInteger capitalRow = [self.picker selectedRowInComponent:CapitalsList];
// Defining the Selected states and selected capital in the row
NSString *selectedState = self.stateList[stateRow];
NSString *selectedCapital = self.capitalList[capitalRow];
// Giving a title to the alert message
NSString *title = [[NSString alloc] initWithFormat:@"You selected %@ and %@", selectedState, selectedCapital];
// Alert Message
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:@"Thats right, +1 for you!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"Great!" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:action];
[self presentViewController:alert animated:YES completion:nil];
// Updating the scores
_rightScore++;
_rightAnswer.text = [NSString stringWithFormat:@"%i", _rightScore];
_scoreTotal = _rightScore - _wrongScore;
_scoreLabel.text = [NSString stringWithFormat:@"Score: %i", _scoreTotal];
} else {
// Defining State & capitalnames by row
NSInteger stateRow = [self.picker selectedRowInComponent:StatesList];
NSInteger capitalRow = [self.picker selectedRowInComponent:CapitalsList];
// Defining the Selected states and selected capital in the row
NSString *selectedState = self.stateList[stateRow];
NSString *selectedCapital = self.capitalList[capitalRow];
// Giving a title to the alert message
NSString *title = [[NSString alloc] initWithFormat:@"You have selected %@ and %@", selectedState, selectedCapital];
// Alert Message
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:@"Thats not correct, -1 for you." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"Let me try again!" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:action];
[self presentViewController:alert animated:YES completion:nil];
// Updating the scores
_wrongScore++;
_wrongAnswer.text = [NSString stringWithFormat:@"%i", _wrongScore];
_scoreTotal = _rightScore - _wrongScore;
_scoreLabel.text = [NSString stringWithFormat:@"Score: %i", _scoreTotal];
}
答案 0 :(得分:0)
您要将所选行分配给两个变量stateRow
和capitalRow
。你似乎想要做的是比较这两个变量,看看它是否具有相同的值,例如if (stateRow == capitalRow) { ... } else { ... }
HTH