Bil*_*hla 7 xcode cocoa-touch objective-c nsfetchedresultscontroller ios
我完全被这个所困扰,无法弄清楚我错过了什么.也许还有很多东西需要了解核心数据.
这是我的Fetched Results Controller,它显示了一个无节表,但我的搜索显示控制器工作:
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.buckyballDatabase.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
Run Code Online (Sandbox Code Playgroud)
鉴于我应用sectionNameKeyPath,添加部分.部分被添加但我的搜索显示控制器坏了,抛出以下错误:
*** Assertion failure in -[UITableViewRowData rectForRow:inSection:], /SourceCache/UIKit_Sim/UIKit-2372/UITableViewRowData.m:1630
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect at invalid index path (<NSIndexPath 0x7481040> 2 indexes [0, 1])'
Run Code Online (Sandbox Code Playgroud)
这里是我的表视图数据源实现其中filteredList是NSArray: -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (tableView == self.tableView)
{
return [[self.fetchedResultsController sections] count];
}
else
{
return 1;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.tableView)
{
return [[[self.fetchedResultsController sections] objectAtIndex:section] numberOfObjects];
}
else
{
return [self.filteredList count];
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (tableView == self.tableView)
{
return [[[self.fetchedResultsController sections] objectAtIndex:section] name];
}
else
{
return nil;
}
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
if (tableView == self.tableView)
{
if (index > 0)
{
return [self.fetchedResultsController sectionForSectionIndexTitle:title atIndex:index-1];
}
else
{
self.tableView.contentOffset = CGPointZero;
return NSNotFound;
}
}
else
{
return 0;
}
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
if (tableView == self.tableView)
{
NSMutableArray *index = [NSMutableArray arrayWithObject:UITableViewIndexSearch];
NSArray *initials = [self.fetchedResultsController sectionIndexTitles];
[index addObjectsFromArray:initials];
return index;
}
else
{
return nil;
}
}
Run Code Online (Sandbox Code Playgroud)
在以下行的cellForRowAtIndexPath中抛出异常: -
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)
请问是否需要提供更多信息..我在这个问题上摸不着头脑.
尝试使用-dequeueReusableCellWithIdentifier:和不使用-dequeueReusableCellWithIdentifier:forIndexPath:.
| 归档时间: |
|
| 查看次数: |
1338 次 |
| 最近记录: |