[英]Switching views without dismissing View
I am developing a small music application in which first view comprises of all the List of songs in Tableview and when user taps on any one row (song) it takes them to Second view & Plays the song their(comprising of play/Pause Buttons). 我正在开发一个小型音乐应用程序,其中的第一个视图包含Tableview中所有歌曲列表,并且当用户点按任一行(歌曲)时,将其带到第二个视图并播放其歌曲(包含播放/暂停按钮) 。 Now I go back in First View from Second View using back button to select another song. 现在,我使用“后退”按钮从第二视图返回“第一视图”,以选择另一首歌曲。 And their is one button in First View for just switching views(ie it takes to current playing song)but it plays that same song from start but not from its currentplaying . 它们是“第一视图”中的一个按钮,仅用于切换视图(即切换到当前播放的歌曲),但它从开始播放同一首歌曲,而不是从当前播放开始播放。 Its similar to now Playing button in Stock Music app in iOS. 它类似于iOS中Stock Music应用中的“正在播放”按钮。 Im using storyboards & Segues 我正在使用情节提要和Segues
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
temp = indexPath.row;
[tableView deselectRowAtIndexPath:indexPath animated:NO];
[self performSegueWithIdentifier:@"Player" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"Player"])
{
MPMediaItem *item = [itemCollections objectAtIndex:temp];
NSString *trackInfo = [[NSString alloc] initWithFormat:@"%@- %@",[item valueForProperty:MPMediaItemPropertyTitle],[item valueForProperty:MPMediaItemPropertyArtist]];
MPMediaItemArtwork *artwork = [item valueForProperty:MPMediaItemPropertyArtwork];
NSURL *tempURL = [item valueForProperty:MPMediaItemPropertyAssetURL];
playerController = [segue destinationViewController];
playerController.fileUrl1 = tempURL;
playerController.globalVar = [NSNumber numberWithInteger:temp];
playerController.labelTitleString = trackInfo;
playerController.img = [artwork imageWithSize:CGSizeMake(100, 100)];
}
} }
You could go about this in many ways -- I would suggest implementing a singleton to handle the media playback. 您可以通过多种方式解决此问题-我建议您实现一个单例来处理媒体播放。 Rather than constantly retaining that view, this singleton manager (part of your model) should provide any controllers with the needed information about the current song, album, author, etc. 这个单例管理器(模型的一部分)应该一直向所有控制器提供有关当前歌曲,专辑,作者等的必要信息,而不是一直保留该视图。
Ex. 例如 In your TableViewController: 在您的TableViewController中:
- (void)viewDidLoad
{
[self setSong:[[PlaybackManager sharedInstance] currentSong]];
if (self.song) {
//Add navigation item
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.