0

我在一个问题上停留了 2 周。
我有一个 UILabel,它在我看来显示 soundPlayer 当前持续时间。我使用 UIPageViewController 让用户像一本真正的书一样浏览页面(我的视图)。但是当另一个视图控制器的一部分出现时,标签不会显示当前进度。(因为这是视图控制器的新实例)。
我怎样才能使这个 UILabel 是静态的?我的意思是 ViewController 的所有实例都可以访问一个 UIlabel,所以它们都只更新一个标签。
我不能使用单例设计模式,因为 UIPageViewController 至少需要我的视图控制器的 2 个实例。
每次创建视图控制器的新实例时,不应分配 soundPlayer。我应该如何解决这个困境?

您可以在天气实时应用程序中看到我的问题示例。见下图: 在此处输入图像描述

下载示例代码:http: //upload.ugm.ac.id/300paging.zip

4

1 回答 1

1

the only change should I did is to create an static AVAudioPlayer

static AVAudioPlayer *soundPlayer;

soundPalyer is Static so there is one for all of instance objects of this class.

and in ViewDidLoad method:

    if (!soundPlayer) {
        soundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error];
    }

so when you navigating from one viewController to another viewController, soundPlayer wont initialized again and continue its playing.
thats all.

于 2013-03-01T07:07:36.550 回答