[英]if statement doesn't seem to work
当date.name
与该应用有关时,我的if语句有一点问题。新闻项目:有人可以帮我吗?
- (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"])
类似于C标准函数strcmp()
, -compare:
在相等的情况下返回0。 尝试
if ([data.name isEqualToString:@"about this app"]) {
// code
}
要么
if (![data.name compare:@"about this app"]) {
// code
}
相反(首选第一种符号)。
如果要检查是否相等,则可能要使用:
isEqualToString:
而不是compare:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.