【发布时间】:2016-06-27 00:18:41
【问题描述】:
这只发生在我第一次以全新方式运行应用程序时,即便如此,当我尝试重新创建以进行调试时,大部分时间它都能正常工作。
我在indexPath.row 选择了这首歌,一切都记录正确,除了 segue 没有被调用。
它调用didSelectRowAtIndexPath,但不调用prepareForSegue。
一切都正确连接,因为如果我再试一次,它会完美运行,didSelectRowAtIndexPath 和 prepareForSegue 都会被调用。 (我只是使用didSelectRowAtIndexPath 进行调试以记录我没有得到零数据。)
有没有人遇到过这个问题,或者对如何调试有任何想法?谢谢!
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MPMediaItem *selectedItem = [[albumsArrayForTVC objectAtIndex:indexPath.section] representativeItem];
NSString *albumDetailTitle = [selectedItem valueForProperty:MPMediaItemPropertyAlbumTitle];
MPMediaQuery *tempAlbumMPMediaQuery = [MPMediaQuery songsQuery];
MPMediaPropertyPredicate *albumPredicate = [MPMediaPropertyPredicate predicateWithValue: albumDetailTitle forProperty: MPMediaItemPropertyAlbumTitle];
[tempAlbumMPMediaQuery addFilterPredicate:albumPredicate];
NSArray *albumTracksArray = [tempAlbumMPMediaQuery items];
MPMediaItem *rowItemSong = [[albumTracksArray objectAtIndex:indexPath.row] representativeItem];
NSLog(@"track: %@", rowItemSong);
NSString *song = [rowItemSong valueForProperty:MPMediaItemPropertyTitle];
NSLog(@"track name: %@", song);
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"nowPlaying"]){
// send to now playing
NSUInteger selectedSection = [[self.tableView indexPathForSelectedRow] section];
NSUInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
NSArray *albumTracksArray = [self albumTracksForSegue:[[albumsArrayForTVC objectAtIndex:selectedSection] representativeItem]];
MPMediaItem *rowItemSong = [[albumTracksArray objectAtIndex:selectedIndex] representativeItem];
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController systemMusicPlayer];
[musicPlayer setQueueWithItemCollection:[MPMediaItemCollection collectionWithItems:albumTracksArray]];
[musicPlayer setNowPlayingItem:rowItemSong];
[musicPlayer play];
NSLog(@"Row Item Song: %@", rowItemSong);
}
}
这很奇怪,因为它不是我每次都能重新创建的东西,这就是为什么我很难弄清楚这里发生了什么,无论是系统音乐播放器的东西还是我的东西代码等
【问题讨论】:
标签: ios objective-c uitableview audio-player mpmediaitem