1

我正在尝试在 Apple 开发人员网站上合并两个示例代码,名为 *2_SimpleSectionedTableView* 和TableSearch
本质上,我希望能够使用 aUISearchBar来过滤带有部分的时区表。下面的代码使我的应用程序崩溃说

不兼容的整数到指针的转换。

这是什么意思,我该如何解决?

- (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]]];
            }
        }
    }
}
}
4

1 回答 1

0

崩溃发生在这里:

[NSIndexPath indexPathWithIndexes:i length:j]

此方法需要一个指针(不是整数!)作为第一个参数:

+ (id)indexPathWithIndexes:(NSUInteger *)indexes length:(NSUInteger)length;   

您应该改用表格视图特定的方法:

+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;
于 2012-07-11T12:31:34.833 回答