我正在构建一个应用程序,我差不多完成了。
麻烦的是:我有一个for循环,其中两个if语句无法正常工作,我只是看不出有什么问题。
以下是代码:
for (Tickets *items in _feedItems){
if ([resultText.text isEqual:(id) items.ticketNumber]) {
if ([items.ticketDate isEqualToString: @"0"]) {
status.text = @“YES”;
NSString *date = resultText.text;
NSMutableString *postString = [NSMutableString
stringWithString:kPostURL];
[postString appendString:[NSString stringWithFormat:@"?%@=%@", kDate,
date]];
[postString setString:[postString
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:
[NSURL URLWithString:postString]];
[request setHTTPMethod:@"POST"];
postConnection = [[NSURLConnection alloc] initWithRequest:request
delegate:self startImmediately:YES];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
UIViewController *View = [storyboard
instantiateViewControllerWithIdentifier:@"Approved"];
[self presentViewController:View animated:NO completion:NULL];
}
break;
}
else {
status.text = @“NO”;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
UIViewController *View = [storyboard
instantiateViewControllerWithIdentifier:@"NotApproved"];
[self presentViewController:View animated:NO completion:NULL];
}
}
这段代码总是把我引向ViewController NotApproved,而且永远不会引用我认可的ViewController;即使它被批准并且执行了对数据库的POST。
任何帮助都是非常有用的!
答案 0 :(得分:1)
if ([resultText.text isEqual:(id) items.ticketNumber])
问题在这里,您正在将字符串与id进行比较。 id可以是String,Array,Dictionary等。首先转换为文本,然后进行比较,否则每次都会抛出错误。