在不同代码集中检索的元数据正在屏幕上显示在同一个字符串上,并用“ - ”分隔它们。如何将每组信息放到他们自己的行或字符串中?
NSDictionary *currentlyPlayingTrackInfo;
NSString *msg = albumInfo;
NSString *newArtist;
NSString *newSongName;
NSRange range = [msg rangeOfString:@" - "];
if (range.location != NSNotFound){
newArtist = [msg substringToIndex:range.location];
newSongName = [msg substringFromIndex:(range.location + range.length)];
}
if (newArtist != nil){
currentlyPlayingTrackInfo = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:newArtist, newSongName, pmAlbumArt, nil] forKeys:[NSArray arrayWithObjects:MPMediaItemPropertyArtist, MPMediaItemPropertyTitle, MPMediaItemPropertyArtwork, nil]];
}else{
currentlyPlayingTrackInfo = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:msg, pmAlbumArt, nil] forKeys:[NSArray arrayWithObjects:MPMediaItemPropertyTitle, MPMediaItemPropertyArtwork, nil]];
}
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentlyPlayingTrackInfo;
}
}
答案 0 :(得分:0)
如果你想把msg保存为一个字符串,你可以用“\ n”替换“ - ”,这会把它分成3行。
NSString *s = @"Artist - Song - Album";
NSString *newString = [s stringByReplacingOccurrencesOfString:@"-" withString:@"\n"];
NSLog(@"%@",newString);