1
我想添加兩個額外的行到我的UITableView。數據來自帶有部分的FetchResultsController。我已經嘗試了通常與數組一起工作的技巧,但他們沒有使用帶有節的FetchResultsController。只需在numberofrows中添加+2不會有幫助。NSFetchedResultCintroller與部分+ UITableView + 2多行
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return ([[fetchedResultsController sections] count]+2);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return ([sectionInfo numberOfObjects]+2);
}
和fetchresultcontroller:
- (NSFetchedResultsController *)fetchedResultsController {
// Set up the fetched results controller if needed.
if (fetchedResultsController != nil) {
return fetchedResultsController;
}
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"eventsEntity" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"eventName" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptors release];
[sortDescriptor release];
NSFetchedResultsController *fetchedResultsController1 =
[[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:managedObjectContext
sectionNameKeyPath:@"eventName" cacheName:nil];
self.fetchedResultsController = fetchedResultsController1;
fetchedResultsController.delegate = self;
[request release];
[fetchedResultsController1 release];
return fetchedResultsController;
}
感謝mvds,現在我明白了...... – 2011-03-12 12:26:44