我正在嘗試使它成爲我的UITableView
總是在底部有一個特定的行,在那裏錨定。用NSFetchedResultsController錨定一行
我正在使用NSFetchedResultsController
執行提取操作,然後是用於檢測合併上下文更改的普通Apple樣板。
我想要做的是在結果底部總是有一行「不是你在找什麼?」。我將如何做到這一點?我對自定義單元格類型感到滿意,但我甚至無法將相同類型的單元格固定到底部。
- (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這會工作,但什麼情況是,無論何時,增加了一個多行比什麼是在fetchedResultsController
代碼一個單元格被更新,Controller的方法'configureCell'被調用,它對SpecialCell一無所知。
從 - (無效)控制器:(NSFetchedResultsController *)控制器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'的'代碼。 – DShah