循环遍历UITableView的各个部分

时间:2012-07-11 03:31:13

标签: objective-c ios xcode pointers integer

我正在尝试在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]]];
            }
        }
    }
}
}

1 个答案:

答案 0 :(得分:0)

崩溃发生在这里:

[NSIndexPath indexPathWithIndexes:i length:j]

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

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

您应该使用特定于表视图的方法:

+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;