gpt4 book ai didi

iphone - 核心数据 bool 属性比较

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:02:50 25 4
gpt4 key购买 nike

我有一个 tableViewController,并且在:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

我有这个代码:

    MinorGoal *minor = [self.array objectAtIndex:indexPath.row];
if (minor.finishedBoolean == [NSNumber numberWithBool:YES]){
// code to make check mark
UITableViewCell *indexPathCell = [tableView cellForRowAtIndexPath:indexPath];
indexPathCell.accessoryType = UITableViewCellAccessoryCheckmark;
NSLog(@"the %@, is finished", minor.title);
}
cell.textLabel.text = minor.title;

我想要的只是检查“minor”的“finishedBoolean”arrtibute,如果是,那么它所在的单元格必须有一个复选标记,当我运行上面的代码时,我得到 NSLog:

        NSLog(@"the %@, is finished", minor.title);

这意味着 if 语句有效,但为什么单元格附件未设置为 checkMark?这是这一行:

        indexPathCell.accessoryType = UITableViewCellAccessoryCheckmark;

谢谢,对不起新手

最佳答案

我猜 CoreData ManagedObject 是 minor 对象,它将使 finishedBoolean 成为 NSNumber

您的检查失败,因为您检查的是两个对象是同一对象。 == 不检查对象的相等值。

有几种方法可以执行 if 语句。

if ([minor.finishedBoolean boolValue])

if ([minor.finishedBoolean isEqualToNumber:@YES])

if ([minor.finishedBoolean boolValue] == YES)

在所有这些中,我会选择第一个。

希望这对您有所帮助。

关于iphone - 核心数据 bool 属性比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18899808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com