I have a little problem with my if statement when date.name
is about this app News item : Does somebody can help me?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MoreMenu *data = [self.fetchedResultsController objectAtIndexPath:indexPath];
if ([data.name compare:@"about this app"]) {
NSLog(@"About this app : %@", data.name);
} else {
NSLog(@"News item : %@", data.name);
}
}
尝试:
if ([data.name isEqualToString:@"about this app"])
Similar to the pattern of the C standard function strcmp()
, -compare:
returns 0 in case of equality. Try
if ([data.name isEqualToString:@"about this app"]) {
// code
}
or
if (![data.name compare:@"about this app"]) {
// code
}
instead (the first notation is preferred).
If you are checking for equality, you probably want to use:
isEqualToString:
instead of compare:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.