Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在UITableView中筛选和处理带有关键字的字符串_Ios_Objective C_Uitableview_Keyword - Fatal编程技术网

Ios 在UITableView中筛选和处理带有关键字的字符串

Ios 在UITableView中筛选和处理带有关键字的字符串,ios,objective-c,uitableview,keyword,Ios,Objective C,Uitableview,Keyword,我对编码相当陌生,我正在制作一个RSS提要类型的应用程序,我想知道是否有一种方法可以在描述中搜索诸如facebook或新闻之类的关键字,然后只将包含关键字的项目处理到我的UITableView 以下是我到目前为止从提要检索描述的代码 - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSStr

我对编码相当陌生,我正在制作一个RSS提要类型的应用程序,我想知道是否有一种方法可以在描述中搜索诸如facebook或新闻之类的关键字,然后只将包含关键字的项目处理到我的UITableView

以下是我到目前为止从提要检索描述的代码

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {

    if ([elementName isEqualToString:@"item"]) {

        link = [NSMutableString stringWithString:
        [link stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
        pubDate = [NSMutableString stringWithString:[pubDate stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];


        [item setObject:author forKey:@"author"];
        [item setObject:link forKey:@"link"];
        [item setObject:description forKey:@"description"];
        [item setObject:pubDate forKey:@"pubDate"];

        item[@"pubDateObj"] = [self dateFromXml:item[@"pubDate"]];


        NSComparator comparator = ^(NSDictionary *a, NSDictionary *b) {
            return [b[@"pubDateObj"] compare:a[@"pubDateObj"]];
        };
        NSUInteger index = [feeds indexOfObject:item
                              inSortedRange:NSMakeRange(0, [feeds count])
                                    options:NSBinarySearchingInsertionIndex
                            usingComparator:comparator];


        [feeds insertObject:[item copy] atIndex:index];

    }
}
当然,更换:

[feeds insertObject:[item copy] atIndex:index];
与:


或者您也可以使用regularExpression。

您可以使用NSRegularExpression或rangeOfString来检测关键字,并决定是否将它们添加到FeedsHanks中以进行回复,因为某些原因,它不会显示与该代码相关的任何内容,我的意思是,如果代码中有关键字,那么我希望它在Rss提要中显示该项目的全部描述。太棒了,这正是我想要的。谢谢你的帮助。嗯……我很高兴,但你应该把这个答案设为正确答案;
NSString *strToEvaluate = item[@"description"];

NSString *word = @"facebook";
NSString *word2 = @"news";

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains[c] %@", word];
NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"SELF contains[c] %@", word2];

if([predicate evaluateWithObject:strToEvaluate] || [predicate2 evaluateWithObject:strToEvaluate]) {
    [feeds insertObject:[item copy] atIndex:index];
}