试图为ios制作音乐播放器,但却会遇到麻烦

时间:2015-05-17 07:46:09

标签: ios audio-player

这是我的项目概述 - >

我有一个用于音乐列表的viewcontroller(A类),从那里用户点击一个音乐,然后将一个url发送到另一个viewcontroller(类Audioplayer)。和Audioplayer类播放这首歌。

代码开始:

-(IBAction)back:(id)sender
{ 
   [self dismissViewControllerAnimated:YES completion:nil];
 }

代码结束。

在Audioplayer类中的

在导航栏中有一个后退按钮。当按下后退按钮时,此代码执行

-(void) Player{ AudioPlayerViewController *audvc = [[AudioPlayerViewController alloc] init];
[self presentViewController:audvc animated:YES completion:nil];}

现在问题是我有一个"正在播放"按钮在A类导航栏(如iphone音乐应用程序)中,我想通过按下"正在播放"来导航所有控制器处于当前状态的Audioplayer类。按钮。

注意我已经尝试了这个但它创建了一个带有新控件的新AudioPlayer类对象。

代码在这里

#include <iostream>
#include <string>
using std::cin; using std::cout; using std::endl; using std::string;

struct Sales_data{
    string bookNo;
    unsigned units_sold = 0;
    double revenue = 0.0;
};

int main()
{
    Sales_data total;
    cin >> total;
} 

但是我希望通过按回按钮我已经解雇的那个视图。

专家请帮帮我,如果你不明白我的问题那么请告诉我,抱歉我的英语不好。

1 个答案:

答案 0 :(得分:0)

AudioPlayerViewController已在您的情节提要中创建,因此您不应该像这样实例化。

您可以通过让故事板向您返回对它的引用来将数据传递给视图控制器:

AudioPlayerViewController *apvc = [self.storyboard instantiateViewControllerWithIdentifier:@"TheVCIdentifier"];

apvc.songurl = item.urls;

//the presentModalViewController method is deprecated.
[self presentViewController:apvc animated:YES completion:nil];

您可以在Interface Builder下的Identity Inspector > Storyboard ID中添加视图控制器的标识符。

enter image description here

另一种选择是为View Controller创建一个带有标识符的手动segue,并在您正在转换的View Controller中实现prepareForSegue方法并实现它:

- (void) didSelectItem:(ListItem *)item {

    [self performSegueWithIdentifier:@"YourSegueIdentifier" sender:self];
}

并在prepareForSegue方法中:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        if ([segue.identifier isEqualToString:@"YourSegueIdentifier"]) {
       AudioPlayerViewController *apvc = [segue destinationViewController];
       apvc.songurl = item.urls;
    }
}

您可以查看Apple关于此事herehere

的文档
相关问题