简体   繁体   English

逐块执行不执行

[英]Block in block doesn’t execute

I have ViewController with -updateUI method. 我有带-updateUI方法的ViewController。 It is needs to be called periodically while AVPlayer plays. AVPlayer播放时需要定期调用它。

So this is in -viewDidLoad (note, self.track is not a AVPlayer instance, it is instance of class Track with almost the same method that AVPlayer has): 因此,这是在-viewDidLoad中(请注意,self.track不是AVPlayer实例,它是Track类的实例,具有与AVPlayer几乎相同的方法):

__weak ViewController * selfWeak = self;
[self.track addPeriodicTimeObserverForInterval:CMTimeMake(1, 20)
                                         queue:dispatch_get_main_queue()
                                    usingBlock:^{
                                        [selfWeak updateUI];
                                        NSLog(@"THIS BLOCK DOESN'T EXECUTE");
}];

This is implementation of this method in Track Class: 这是Track类中此方法的实现:

- (void) addPeriodicTimeObserverForInterval:(CMTime)interval
                                      queue:(dispatch_queue_t)queue
                                 usingBlock:(void (^)(void))block
{
        self.periodicObserverBlock = block;
        self.observeQueue = queue;
        self.observeInterval = interval;
        self.waitingToObserve = YES;
}

Property declaration: 财产申报:

typedef void(^observeHandler)();
@property (nonatomic, strong) observeHandler periodicObserverBlock;
@property (nonatomic) CMTime observeInterval;
@property (nonatomic) dispatch_queue_t observeQueue;

I'm saving it for time, when AVPlayer ready. 当AVPlayer准备好时,我正在节省时间。 When it is ready, I'm doing this: 准备就绪后,我正在这样做:

- (void) afterLoadingMethod
{
        __weak Track *selfWeak = self;
        [self.player addPeriodicTimeObserverForInterval:self.observeInterval
                                                  queue:self.observeQueue
                                             usingBlock:^(CMTime t){
                                                 (void) selfWeak.periodicObserverBlock;
                                                 NSLog(@“THIS BLOCK EXECUTES”);
                                             }];
}

The problem is that block that says -updateUI doesn't execute. 问题是说-updateUI的代码块不执行。 (It is marked with NSLog(@“THIS BLOCK DOESN'T EXECUTE)). (它标记为NSLog(@“此块不执行”))。 Block that calling in Track class executes. 阻止Track类中的调用执行。 So I think problem is somewhere in storing properties, somewhere here 所以我认为问题出在存储属性的某个地方

self.periodicObserverBlock = block;

Or here: 或在这里:

@property (nonatomic, strong) observeHandler periodicObserverBlock;

But I didn't figured it out. 但是我没有弄清楚。 Thanks in advance. 提前致谢。

You're just referencing the block: 您只是在引用该块:

(void) selfWeak.periodicObserverBlock;

To call the block, use parenthesis: 要调用该块,请使用括号:

selfWeak.periodicObserverBlock();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM