0

我试图替换数组中的文本,由于某种原因,代码不起作用,尽管 Xcode 没有行警报,但它会导致它崩溃。

即“名称,2013”

剥离“,2013”

以导致

“姓名”

我做错了什么,为了我的生活,我无法解决这个问题并且迫切需要帮助?

有问题的特定行是“case ITSectionTypeAuthor:”

- (void)setUpDataByType:(ITSectionType) type andFilter:(NSString *)filter {
    self.type = type;
    self.filter = (filter)? filter : @"";
    [self.sections removeAllObjects];
    NSPredicate *predicate = nil;
    NSString *descriptorKey = @"genus";
    NSArray *rowData = [[ITData sharedObject] animals]; //coming form singleton

    //generate predicate

    switch (self.type) {

        case ITSectionTypeAuthor:
            predicate = [NSPredicate predicateWithFormat:@"describer componentsSeparatedByString:@", "] objectAtIndex:0] LIKE %@", filter];
            break;

        default:
            predicate = nil;
            break;
 }
4

1 回答 1

1

我认为问题出在这一行:

predicate = [NSPredicate predicateWithFormat:@"describer componentsSeparatedByString:@", "] objectAtIndex:0] LIKE %@", filter];

您正在创建一个objective-c 字符串:

@"describer componentsSeparatedByString:@"

然后是一个 C 字符串:

"] objectAtIndex:0] LIKE %@"

这不可能是对的,不是吗?我想你想要:

predicate = [NSPredicate predicateWithFormat:@"describer LIKE %@", [[filter componentsSeparatedByString:@", "] objectAtIndex:0]];
于 2013-06-06T19:30:14.940 回答