【发布时间】:2016-08-13 15:40:31
【问题描述】:
我是初学者,也许这是一个微不足道的问题。 我有这个方法:
-(NSString *)getInfoFormediaItem:(MPMediaItemCollection *)list {
NSString *trackCount;
if ([list count] > 0) {
trackCount = [NSString stringWithFormat:NSLocalizedString(@"%lu Songs", @""), (unsigned long)[list count]];
} else if([list count] == 1) {
trackCount = [NSString stringWithFormat:NSLocalizedString(@"1 Song", @"")];
} else {
trackCount = [NSString stringWithFormat:NSLocalizedString(@"0 Song", @"") ];
}
return [NSString stringWithFormat:@"%@", trackCount];
}
我想在这里用 MPMediaItemCollection 调用它:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if( cell == nil )
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
}
MPMediaQuery *playlistsQuery = [MPMediaQuery playlistsQuery];
NSArray *playl = [playlistsQuery collections];
MPMediaItem *rowItem = [playl objectAtIndex:indexPath.row];
MPMediaItemCollection * collection = [[MPMediaItemCollection alloc] initWithItems:[NSArray arrayWithObject:rowItem]];
cell.detailTextLabel.text = [self getInfoFormediaItem:collection];
}
我想获取每个播放列表中的曲目数。 它不起作用。我该如何解决?提前致谢!
【问题讨论】:
-
你在那里进行的执行选择器没有必要而且有点奇怪。它始终为 0 的原因是因为您从不将参数传递给您的方法。所以 [nil count] 总是 0。你应该直接调用它。 [self getInfoForMediaItem: someMPMediaItemCollection];
标签: ios objective-c nsstring mpmediaitemcollection