【发布时间】:2011-11-06 17:08:06
【问题描述】:
我正在努力让我的UITableView 总是在底部有一个特定的行,固定在那里。
我使用NSFetchedResultsController 执行提取,然后使用常规 Apple 样板来检测合并的上下文更改。
我想要做的是始终在结果底部显示一行,“不是您要查找的内容?”。我该怎么做?我对自定义单元格类型感到满意,但我什至无法将相同类型的单元格锚定到底部。
比 fetchedResultsController 中的内容多添加一行的代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return[sectionInfo numberOfObjects]+1;
}
cellForRowForIndexPath 的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifierNormal = @"NormalCell";
UITableViewCell *cell = nil;
cell = [tableView CellIdentifierNormal];
if (cell == nil) {
cell = [[NormalCell createCell]autorelease];
}
// For regular results, go configure the cell. For the extra 'Special Row' at bottom, assign it the Special cell.
if([indexPath indexAtPosition:0] <= [[[fetchedResultsController sections] objectAtIndex:0] numberOfObjects])
[self configureCell:cell atIndexPath:indexPath];
else {
if (cell == nil) {
cell = [[SpecialCell createCell] autorelease];
}
SpecialCell *nc = (SpecialCell*)cell;
nc.labelFirstLine.text = @"Not What You're Looking For?";
}
return cell;
}
如果不使用 NSFetchedResultsController,这将起作用,但发生的情况是,每当更新单元格时,都会从控制器调用方法 'configureCell',而控制器对 SpecialCell 一无所知。
来自 - (void)controller:(NSFetchedResultsController *)controller didChangeObject:......
case NSFetchedResultsChangeUpdate:
[self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
break;
这里是configureCell:
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
// Configure the cell
// Go get it from coredata
NormalCell *vc = (NormalCell*)cell;
NormalObject *no = (NormalCell *)[fetchedResultsController objectAtIndexPath:indexPath];
....<ASSIGNMENT TO CELL HERE>....
}
【问题讨论】:
-
如需更好的答案,请发
cellForRowAtIndex的代码。
标签: ios uitableview anchor nsfetchedresultscontroller