Je suis un débutant et c'est peut-être une question triviale. J'ai cette méthode:appel NSString avec plusieurs paramètres
-(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];
}
Je voudrais appeler ici avec un 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];
}
Je voudrais obtenir le nombre de pistes dans chaque liste de lecture. Cela ne fonctionne pas. Comment puis-je résoudre? Merci d'avance!
La fonction de sélecteur que vous utilisez n'est pas nécessaire et un peu étrange. La raison pour laquelle c'est toujours 0 est parce que vous ne passez jamais un argument dans votre méthode. Donc [nombre nul] est toujours 0. Vous devriez appeler cela directement. [self getInfoForMediaItem: someMPMediaItemCollection]; – Dare