容器视图中的IBOutlets为零

时间:2013-11-20 23:34:46

标签: ios iphone objective-c iboutlet

我正在开发一款应用程序,其中包括在歌曲中适当的时间突出显示歌词。我这样做的方法并不好,但是直到我将带有歌词的视图控制器移动到呈现视图控制器中的容器视图中。应用程序的流程如下:按下播放按钮,包含歌词的视图控制器进入视图,并设置计时器并递增计数器。当计数器在特定时间之间时,包含相应单词的UILabel会更改其文本颜色属性。这之前工作正常,但现在它在容器视图中指向标签的IBOutlets是零。如果我查看故事板,我可以清楚地看到它们是连接的。但是,我在容器视图控制器上插入了一个带有IBAction的按钮,通过该方法,我可以更改任何标签的背景颜色。那么有人知道为什么标签会是零吗?

这是我启动计时器的地方:

self.timer = [NSTimer scheduledTimerWithTimeInterval:0.02f target:self selector:@selector(highlightWord) userInfo:nil repeats:YES];

和highlightWord就在这里(绝对不是最漂亮的代码,但我想不出更好的方法。属性的名称是指我想要突出显示的单词)这是非常重复的,所以你不应该通读整个东西。只知道当我在这个方法中设置一个断点时,所有的IBOutlet都是nil.Also,“seconds”是一个整数计数器,我在初始化定时器时将其设置为零:

- (void)highlightWord {
    // 1
    if (!paused) {
        [self setAllLyricsToWhite];
        seconds += 0.02;
        NSLog(@"%f", seconds);

        if (seconds >= 0 && seconds <=3.48) {

            [self setAllLyricsToWhite];

            self.cheer.textColor = [UIColor blackColor];
        } else if (seconds >= 3.74 && seconds <= 3.8) {

            [self setAllLyricsToWhite];
            self.cincinnati.textColor = [UIColor blackColor];
        }else if (seconds >= 5.1 && seconds <= 5.2) {

            [self setAllLyricsToWhite];
            self.cincy.textColor = [UIColor blackColor];
        }else if (seconds >= 5.4 && seconds <= 5.5) {

            [self setAllLyricsToWhite];
            self.will.textColor = [UIColor blackColor];
        }else if (seconds >= 5.8 && seconds <= 6.1) {
            [self setAllLyricsToWhite];
            self.win.textColor = [UIColor blackColor];
        }else if (seconds >= 6.8 && seconds <= 7.0) {
            [self setAllLyricsToWhite];
            self.fight1.textColor = [UIColor blackColor];
        }else if (seconds >= 7.04 && seconds <= 7.2) {

            [self setAllLyricsToWhite];
            self.to1.textColor = [UIColor blackColor];
        }else if (seconds >= 7.36 && seconds <= 7.4) {

            [self setAllLyricsToWhite];
            self.the1.textColor = [UIColor blackColor];
        }else if (seconds >= 7.5 && seconds <= 7.7) {

            [self setAllLyricsToWhite];
            self.finish.textColor = [UIColor blackColor];
        }else if (seconds >= 8.46 && seconds <= 8.5) {

            [self setAllLyricsToWhite];
            self.never.textColor = [UIColor blackColor];
        }else if (seconds >= 8.98 && seconds <= 9.0) {
            [self setAllLyricsToWhite];
            self.give1.textColor = [UIColor blackColor];
        }else if (seconds >= 9.28 && seconds <= 9.34) {
            [self setAllLyricsToWhite];
            self.inLabel.textColor = [UIColor blackColor];
        }else if (seconds >= 9.4 && seconds <= 9.5) {
            [self setAllLyricsToWhite];
            self.rah1.textColor = [UIColor blackColor];
        }else if (seconds >= 9.503 && seconds <= 9.6) {
            [self setAllLyricsToWhite];
            self.rah2.textColor = [UIColor blackColor];
        }else if (seconds >= 9.61 && seconds <= 9.7) {
            [self setAllLyricsToWhite];
            self.rah3.textColor = [UIColor blackColor];
        }else if (seconds >= 10.15 && seconds <= 10.36) {
            [self setAllLyricsToWhite];
            self.youLabel.textColor = [UIColor blackColor];
        }else if ( seconds >= 10.38 && seconds <= 10.46){
            [self setAllLyricsToWhite];
            self.do1.textColor = [UIColor blackColor];
        }else if (seconds >= 10.78 && seconds <= 10.9) {
            [self setAllLyricsToWhite];
            self.your.textColor = [UIColor blackColor];
        }else if (seconds >= 10.98 && seconds <= 11.2) {
            [self setAllLyricsToWhite];
            self.best.textColor = [UIColor blackColor];
        }else if (seconds >= 11.4 && seconds <= 11.6) {
            [self setAllLyricsToWhite];
            self.boys1.textColor = [UIColor blackColor];
        }else if (seconds >= 11.7 && seconds <= 11.8) {
            [self setAllLyricsToWhite];
            self.weWillLabel.textColor = [UIColor blackColor];
        }else if (seconds >= 11.85 && seconds <= 12.0) {
            [self setAllLyricsToWhite];
            self.do2.textColor = [UIColor blackColor];
        }else if (seconds >= 12.1 && seconds <= 12.3) {
            [self setAllLyricsToWhite];
            self.the2.textColor = [UIColor blackColor];
        }else if (seconds >= 12.6 && seconds <= 12.8) {
            [self setAllLyricsToWhite];
            self.rest.textColor = [UIColor blackColor];
        }else if (seconds >= 12.98 && seconds <= 13.1) {
            [self setAllLyricsToWhite];
            self.boys2.textColor = [UIColor blackColor];
        }else if (seconds >= 13.4 && seconds <= 13.6) {
            [self setAllLyricsToWhite];
            self.onward.textColor = [UIColor blackColor];
        }else if (seconds >= 14.2 && seconds <= 14.3) {
            [self setAllLyricsToWhite];
            self.to2.textColor = [UIColor blackColor];
        }else if (seconds >= 14.3 && seconds <= 14.5) {
            [self setAllLyricsToWhite];
            self.victory.textColor = [UIColor blackColor];
        }else if (seconds >= 16.8 && seconds <= 16.9){
            [self setAllLyricsToWhite];
            self.go1.textColor = [UIColor blackColor];
        }else if (seconds >= 17.58 && seconds <= 17.62){
            [self setAllLyricsToWhite];
            self.red.textColor = [UIColor blackColor];
        }else if (seconds >= 18.6 && seconds <= 18.7) {
            [self setAllLyricsToWhite];
            self.go2.textColor = [UIColor blackColor];
        }else if (seconds >= 19.2 && seconds <= 19.3){
            [self setAllLyricsToWhite];
            self.black.textColor = [UIColor blackColor];
        }else if (seconds >= 20.3 && seconds <= 20.4){
            [self setAllLyricsToWhite];
            self.go3.textColor = [UIColor blackColor];
        }else if (seconds >= 21.2 && seconds <= 21.3){
            [self setAllLyricsToWhite];
            self.bearcats.textColor = [UIColor blackColor];
        }else if (seconds >= 22.03 && seconds <= 22.200){
            [self setAllLyricsToWhite];
            self.fight2.textColor = [UIColor blackColor];
        }else if (seconds >= 22.24 && seconds <= 22.400){
            [self setAllLyricsToWhite];
            self.fight3.textColor = [UIColor blackColor];
        }else if (seconds >= 22.8 && seconds <= 22.9){
            [self setAllLyricsToWhite];
            self.fight4.textColor = [UIColor blackColor];
        }else if (seconds >= 23.4 && seconds <= 23.5){
            [self setAllLyricsToWhite];
            self.give2.textColor = [UIColor blackColor];
        }else if (seconds >= 23.51 && seconds <= 23.6){
            [self setAllLyricsToWhite];
            self.me.textColor = [UIColor blackColor];
        }else if (seconds >= 23.61 && seconds <= 23.7){
            [self setAllLyricsToWhite];
            self.a1.textColor = [UIColor blackColor];
        }else if (seconds >= 23.8 && seconds <= 23.9){
            [self setAllLyricsToWhite];
            self.B.textColor = [UIColor blackColor];
        }else if (seconds >= 24.4 && seconds <= 24.5){
            [self setAllLyricsToWhite];
            self.e.textColor = [UIColor blackColor];
        }else if (seconds >= 25.5 && seconds <= 25.6){
            [self setAllLyricsToWhite];
            self.a.textColor = [UIColor blackColor];
        }else if (seconds >= 26.0 && seconds <= 26.1){
            [self setAllLyricsToWhite];
            self.r.textColor = [UIColor blackColor];
        }else if (seconds >= 27.15 && seconds <= 27.3){
            [self setAllLyricsToWhite];
            self.c.textColor = [UIColor blackColor];
        }else if (seconds >= 27.5 && seconds <= 27.6) {
            [self setAllLyricsToWhite];
            self.a2.textColor = [UIColor blackColor];
        }else if (seconds >= 27.9 && seconds <= 28.1) {
            [self setAllLyricsToWhite];
            self.t.textColor = [UIColor blackColor];
        }else if (seconds >=28.3  && seconds <= 28.4) {
            [self setAllLyricsToWhite];
            self.s.textColor = [UIColor blackColor];
        }else if (seconds >= 28.8 && seconds <= 28.9) {
            [self setAllLyricsToWhite];
            self.go4.textColor = [UIColor blackColor];
        }else if (seconds >= 29.3 && seconds <= 29.5) {
            [self setAllLyricsToWhite];
            self.UC.textColor = [UIColor blackColor];
        }else if(seconds >= 30.4 && seconds < 42.08) {
            [self setAllLyricsToWhite];
        }else if(seconds >= 44.0 && seconds <= 44.8) {
            [self setAllLyricsToWhite];
            self.B.textColor = [UIColor blackColor];
        }else if(seconds >= 45.7 && seconds <= 45.8) {
            [self setAllLyricsToWhite];
            self.e.textColor = [UIColor blackColor];
        }else if(seconds >= 47.4 && seconds <= 48.0) {
            [self setAllLyricsToWhite];
            self.a.textColor = [UIColor blackColor];
        }else if(seconds >= 49.05 && seconds <= 50.0) {
            [self setAllLyricsToWhite];
            self.r.textColor = [UIColor blackColor];
        }else if(seconds >= 50.6 && seconds <= 50.8) {
            [self setAllLyricsToWhite];
            self.c.textColor = [UIColor blackColor];
        }else if(seconds >= 52.4 && seconds <= 52.5) {
            [self setAllLyricsToWhite];
            self.a2.textColor = [UIColor blackColor];
        }else if(seconds >= 54 && seconds <= 54.2) {
            [self setAllLyricsToWhite];
            self.t.textColor = [UIColor blackColor];
        }else if(seconds >= 55.8 && seconds <= 56.2) {
            [self setAllLyricsToWhite];
            self.s.textColor = [UIColor blackColor];
        }else if(seconds >= 57.44 && seconds <= 57.5) {
            [self setAllLyricsToWhite];
            self.B.textColor = [UIColor blackColor];
        }else if(seconds >= 57.84 && seconds <= 57.9) {
            [self setAllLyricsToWhite];
            self.e.textColor = [UIColor blackColor];
        }else if(seconds >= 58.1 && seconds <= 58.16) {
            [self setAllLyricsToWhite];
            self.a.textColor = [UIColor blackColor];
        }else if(seconds >= 58.6 && seconds <= 58.7) {
            [self setAllLyricsToWhite];
            self.r.textColor = [UIColor blackColor];
        }else if(seconds >= 59.06 && seconds <= 59.2) {
            [self setAllLyricsToWhite];
            self.c.textColor = [UIColor blackColor];
        }else if(seconds >= 59.46 && seconds <= 59.5) {
            [self setAllLyricsToWhite];
            self.a2.textColor = [UIColor blackColor];
        }else if(seconds >= 59.9 && seconds <= 60.0) {
            [self setAllLyricsToWhite];
            self.t.textColor = [UIColor blackColor];
        }else if(seconds >= 60.2 && seconds <= 60.3) {
            [self setAllLyricsToWhite];
            self.s.textColor = [UIColor blackColor];
        }else if(seconds >= 60.6 && seconds <= 60.8) {
            [self setAllLyricsToWhite];
            self.B.textColor = [UIColor blackColor];
        }else if(seconds >= 62.26 && seconds <= 62.3) {
            [self setAllLyricsToWhite];
            self.e.textColor = [UIColor blackColor];
        }else if(seconds >= 63.9 && seconds <= 63.98) {
            [self setAllLyricsToWhite];
            self.a.textColor = [UIColor blackColor];
        }else if(seconds >= 65.5 && seconds <= 65.58) {
            [self setAllLyricsToWhite];
            self.r.textColor = [UIColor blackColor];
        }else if(seconds >= 67.36 && seconds <= 67.4) {
            [self setAllLyricsToWhite];
            self.c.textColor = [UIColor blackColor];
        }else if(seconds >= 69.02 && seconds <= 69.1) {
            [self setAllLyricsToWhite];
            self.a2.textColor = [UIColor blackColor];
        }else if(seconds >= 70.7 && seconds <= 70.78) {
            [self setAllLyricsToWhite];
            self.t.textColor = [UIColor blackColor];
        }else if(seconds >= 72.4 && seconds <= 72.48) {
            [self setAllLyricsToWhite];
            self.s.textColor = [UIColor blackColor];
        }



        else if(seconds >= 74.1 && seconds <= 74.3) {
            [self setAllLyricsToWhite];
            self.B.textColor = [UIColor blackColor];
        }else if(seconds >= 74.5 && seconds <= 74.6) {
            [self setAllLyricsToWhite];
            self.e.textColor = [UIColor blackColor];
        }else if(seconds >= 75.0 && seconds <= 75.2) {
            [self setAllLyricsToWhite];
            self.a.textColor = [UIColor blackColor];
        }else if(seconds >= 75.4 && seconds <= 75.6) {
            [self setAllLyricsToWhite];
            self.r.textColor = [UIColor blackColor];
        }else if(seconds >= 75.8 && seconds <= 75.98) {
            [self setAllLyricsToWhite];
            self.c.textColor = [UIColor blackColor];
        }else if(seconds >= 76.2 && seconds <= 76.4) {
            [self setAllLyricsToWhite];
            self.a2.textColor = [UIColor blackColor];
        }else if(seconds >= 76.6 && seconds <= 76.8) {
            [self setAllLyricsToWhite];
            self.t.textColor = [UIColor blackColor];
        }else if(seconds >= 77.0 && seconds <= 77.2) {
            [self setAllLyricsToWhite];
            self.s.textColor = [UIColor blackColor];
        }else if(seconds >= 77.3 && seconds <= 77.9) {
            [self setAllLyricsToWhite];
            self.B.textColor = [UIColor blackColor];
            self.e.textColor = [UIColor blackColor];
            self.a.textColor = [UIColor blackColor];
            self.r.textColor = [UIColor blackColor];
            self.c.textColor = [UIColor blackColor];
            self.a2.textColor = [UIColor blackColor];
            self.t.textColor = [UIColor blackColor];
            self.s.textColor = [UIColor blackColor];
        }
    }


    // 2
    if (seconds >= 79) {
        [self setAllLyricsToWhite];
        [self.timer invalidate];
        self.timer = nil;
    }
}

仅出于测试目的,这里的IBAction连接到一个实际上能够引用标签的按钮。他们在这里不是零:

- (IBAction)highlightLabelTest:(id)sender {
    [self.label setTextColor:[UIColor blueColor]];
}

感谢您的帮助。

修改

在viewDidLoad中打印出几个标签之一的描述后,这是我在控制台中看到的:

Spirit[18200:70b] *****Label:<UILabel: 0xc402050; frame = (58 23; 68 21); text = 'Cheer'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xc4020f0>>
2013-11-20 21:32:49.200 Bearcat Spirit[18200:70b] *****Label:(null)
2013-11-20 21:32:49.200 Bearcat Spirit[18200:70b] *****Label:(null)
2013-11-20 21:32:49.200 Bearcat Spirit[18200:70b] *****Label:(null)

所以它似乎从set开始,然后以某种方式设置为null。我很困惑为什么viewDidLoad会被调用四次。

如果我在我的计时器正在使用的方法中的任何地方设置了断点,那么这就是我看到的内容(highlightWord):

debugger output

0 个答案:

没有答案