简体   繁体   English

在不关闭视图的情况下切换视图

[英]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.

相关问题 在不重置第一视图的情况下切换视图 - Switching views without first view being reset 在没有导航控制器的情况下切换视图 - switching views without navigation controller 关闭没有 NavigationController 的推送视图 controller - Dismissing Pushed view controller without NavigationController 在2个不同的View Controller中的2个View之间切换 - Switching between 2 Views in 2 distinct View Controllers 关闭根视图控制器而不显示嵌套/中间视图控制器 - Dismissing to root view controller without showing nested / intermediate view controller 在应用开始关闭带有动画的视图后,关闭不带有动画的视图 - dismiss view without animation after app started dismissing the view with animation 在没有导航菜单的情况下使用ECSliding切换视图 - Switching views with ECSliding without navigation menu UITabBarButton无需切换到另一个视图 - UITabBarButton without switching to another view 如何在不删除整个堆栈的情况下关闭导航控制器中的视图控制器 - How to dismiss a view controller in a navigation controller, without dismissing the whole stack Xcode 在不关闭键盘的情况下切换文本字段时的约束中断 - Xcode Constraint Break When Switching Between Text Fields Without Dismissing Keyboard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM