【发布时间】:2013-12-31 16:57:43
【问题描述】:
我是 Core Data 的新手,我正在构建一个音乐库应用程序,它有两个选项卡:
songs 和 artists 选项卡,显示艺术家列表每个艺术家的总歌曲数和总歌曲持续时间(同样是每个艺术家行)
我的核心数据对象:
Song
=====
name
duration
album
artist (to one relationship)
Artist
======
name
songs (to many relationship)
所以现在我可以显示艺术家列表,以及每个艺术家的歌曲总数:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// i know i should reuse the cells..
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
Artist *artist = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:@"%@ %lu", artist.name, (unsigned long)artist.songs.allObjects.count];
return cell;
}
我有两个问题:
- 这是获取每位艺术家的歌曲总数的正确方法吗?当我打电话给
artist.songs.allObjects.count时,核心数据会获取所有歌曲吗?因为我真的不需要歌曲对象.. - 就像我说的,我还需要每个艺术家都有其所有歌曲的总时长,我怎样才能得到它? (同样不加载所有歌曲对象)
【问题讨论】:
标签: ios iphone objective-c core-data nsfetchedresultscontroller