Xcode 带节的NSFetchedResultCintroller+;UITableView+;另外两行
我正在尝试向UITableView添加两行额外的内容。数据来自带有节的FetchResultsController。我已经尝试了通常适用于数组的技巧,但它们不适用于带节的FetchResultsController。简单地在numberofrows中添加+2没有帮助Xcode 带节的NSFetchedResultCintroller+;UITableView+;另外两行,xcode,uitableview,nsfetchedresultscontroller,rows,Xcode,Uitableview,Nsfetchedresultscontroller,Rows,我正在尝试向UITableView添加两行额外的内容。数据来自带有节的FetchResultsController。我已经尝试了通常适用于数组的技巧,但它们不适用于带节的FetchResultsController。简单地在numberofrows中添加+2没有帮助 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. retur
- (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);
}
首先尝试获取不同概念的图形:节包含行 因此,如果要添加两行,可以将它们添加到现有节中,也可以添加另一节并在该节中放置两行 这可能是最干净的解决方案,所以这里的交易:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return ([[fetchedResultsController sections] count]+1); // +1 for your section
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
NSArray *sections = [fetchedResultsController sections];
if ( section < [sections count] )
{
// the normal case, e.g. sections 0,1,2 of section.count==3
id <NSFetchedResultsSectionInfo> sectionInfo = [sections objectAtIndex:section];
return [sectionInfo numberOfObjects];
} else {
// your own section, e.g. the 4th section, where the FRC returned 3 sections
return 2;
}
}
-(NSInteger)节数表视图:(UITableView*)表视图{
//返回节数。
返回([[fetchedResultsController分区]计数]+1);//+1用于分区
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
//返回节中的行数。
NSArray*节=[fetchedResultsController节];
如果(节<[节计数])
{
//正常情况,例如第0、1、2节。计数=3
id sectionInfo=[sections objectAtIndex:section];
返回[sectionInfo numberOfObjects];
}否则{
//您自己的部分,例如第四部分,其中FRC返回了3个部分
返回2;
}
}
当然,在返回单元格、标题、行高度等的方法中也需要类似的修改
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return ([[fetchedResultsController sections] count]+1); // +1 for your section
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
NSArray *sections = [fetchedResultsController sections];
if ( section < [sections count] )
{
// the normal case, e.g. sections 0,1,2 of section.count==3
id <NSFetchedResultsSectionInfo> sectionInfo = [sections objectAtIndex:section];
return [sectionInfo numberOfObjects];
} else {
// your own section, e.g. the 4th section, where the FRC returned 3 sections
return 2;
}
}