Sha*_*man 5 core-data objective-c ios
看一下Music.app(或iPod.app).根相册视图具有"所有歌曲"行.根歌曲视图有一个"随机"行.根播放列表视图具有"添加播放列表..."行.静态数据混合在同一个UITableView中(可能是)Core Data数据.我想知道Apple是如何实现这一目标的.
我尝试了两种不同的方法,都失败了.像Music.app一样,我的视图在tableHeaderView中也有一个UISeachBar.我第一次尝试保持跟踪有多少"静态"行我有和调整提供给各种的UITableView并要求部分和行信息NSFetchedResultsController方法indexPath.在我实现NSFetchedResultsControllerDelegate方法以允许创建,编辑和删除之前,一切都运行良好.该insertRowsAtIndexPaths:withRowAnimation:方法(以及类似的)大干快上我的调整indexPaths绊倒.默认的indexPaths也不起作用.
我的第二次尝试在其中嵌套另一个UITableView中在我的主要的UITableView的tableHeaderView要用于静态行(并安置在它自己的tableHeaderView的UISeachBar).这种方法甚至没有进入可编辑的阶段.在结束的UISearchBar了由根的UITableView的sectionIndex洗涤重叠和滚动的短名单时,不会再向上滑动的UINavigationBar的后面.
因此,我不是要诊断我的具体问题,而是在寻求关于Apple如何实现这一目标的建议.它们可以是获取数据一次,在一个NSArray缓存它和构建部和行,其包括静态和核心数据行的嵌套的NSArray?
我最近遇到了同样的问题。我想在表格顶部添加一行,其中包含一些静态内容(所有歌曲)。我通过简单地为第 0 部分插入我自己的部分,然后增加核心数据部分来解决这个问题。0 变成 1,1 变成 2,等等。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [_fetchedResultsController sections] + 1;
}
- (NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section {
if( section == 0 ) {
return 1;
}
id <NSFetchedResultsSectionInfo> sectionInfo = [[_fetchedResultsController sections] objectAtIndex:section-1];
return [sectionInfo numberOfObjects];
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// All Charts
if( indexPath.section == 0 && indexPath.row == 0 ) {
// Set up the custom cell
}
// Sets
else {
// Set up the core data cells
}
}
Run Code Online (Sandbox Code Playgroud)
剩下的只是在删除行等时调整索引路径部分的问题。
| 归档时间: |
|
| 查看次数: |
752 次 |
| 最近记录: |