mardi 28 juin 2016

didSelectRowAtIndexPath gets called but not prepareForSegue

This only happens when I've run the app fresh for the first time, and even then, when I try to recreate to debug, most of the time it works correctly.

I select the song at the indexPath.row, and everything logs correctly, except the segue doesn't get called.

It calls didSelectRowAtIndexPath, but doesn't call prepareForSegue.

Everything is hooked up right, because if I try it again it works perfectly and both didSelectRowAtIndexPath and prepareForSegue get called. (I'm just using didSelectRowAtIndexPath for debugging to log that I'm not getting nil data.)

Has anyone run into this, or have any ideas of how to debug this? Thanks!

- (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);
    }
}

enter image description here

It's a weird one because its not something that I can recreate every time, thats why its extra hard for me to figure out what's going on here, whether it's something with the system music player or whether it's something in my code, etc.

Aucun commentaire:

Enregistrer un commentaire