【发布时间】:2012-07-10 15:03:01
【问题描述】:
我正在尝试在 Apple 开发者网站上合并两个示例代码,名为 *2_SimpleSectionedTableView* 和 TableSearch。
本质上,我希望能够使用UISearchBar 过滤带有部分的时区表。下面的代码使我的应用程序崩溃,说
整数到指针的转换不兼容。
这是什么意思,我该如何解决?
- (void)filterContentForSearchText:(NSString*)searchText
{
/*
Update the filtered array based on the search text and scope.
*/
[self.filteredListContent removeAllObjects]; // First clear the filtered array.
/*
Search the main list for products whose type matches the scope (if selected) and whose name matches searchText; add items that match to the filtered array.
*/
for (NSInteger i=0; i<[self.regions count]; i++)
{
Region *region = [self.regions objectAtIndex:i];
for (NSInteger j=0; j<[region.timeZoneWrappers count]; j++) {
{
NSComparisonResult result = [[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathWithIndexes:i length:j] ].textLabel.text compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame)
{
[self.filteredListContent addObject:[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathWithIndexes:i length:j]]];
}
}
}
}
}
【问题讨论】:
-
注意:不需要重复
Region *region = [self.regions objectAtIndex:j];这一行 -
另外,您是否尝试比较字符串以确定 searchText 是否与 localeName 的开头完全相同?
-
是的,所以在示例中,如果您搜索“ip”,则结果会显示 iPhone、ipod 等。但是,如果您搜索“iphone”,结果将返回 nil。
-
k,NSString 有一个方法
hasPrefix对你来说可能更简洁:developer.apple.com/library/mac/#documentation/Cocoa/Reference/… -
谢谢,但目前我无法获得特定的单元格。我正在寻找类似于 cellforrowatindexpath 方法的东西。我可以在这段代码中使用类似的东西吗?
标签: objective-c ios xcode pointers integer