2

I have the following code which should make drawFrame be called every frame but it doesn't:

- (void)viewDidLoad
{
    [super viewDidLoad];
    displayLink = [viewReference.window.screen displayLinkWithTarget:(self) selector:@selector(drawFrame)];
    [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}


- (void) drawFrame:(CADisplayLink*)sender
{
    thel.text = @"test";
}

dispayLink is a pointer to CADisplayLink. thel is connected to a label in my view. This view is connected to viewReference. self is the ViewController. drawFrame is declared

- (void) drawFrame:(CADisplayLink*)sender;

thel.text can be set when I test it in viewDidLoad.

It seems drawFrame is never called. The application is based on Xcode 4.2s empty application template with a custom storyboard file (I added it afterwards rather than selecting use storyboard on creation). It is empty besides the view controller, the view and the label.

I'm new to this. When calling [[NSRunLoop currentRunLoop] run] iOS 5.0 Simulator doesn't display the app at all. The currentRunLoop should be the default main runLoop anyway.

juliomalegria
  • 24,229
  • 14
  • 73
  • 89
Lars
  • 163
  • 4
  • 12

1 Answers1

2

Perhaps you need to set the CADisplaylink 'frameInterval' property:

displayLink.frameInterval = someRate (1-60);

Another interesting curiosity is that

weak private var _anim : CADisplayLink? // mysteriously does nothing

display links, for unknown reasons, simply don't run if the variable is weak.

private var _anim : CADisplayLink? // rock on
Fattie
  • 27,874
  • 70
  • 431
  • 719
spring
  • 18,009
  • 15
  • 80
  • 160
  • this didn't do it unfortunately. – Lars Jan 22 '12 at 19:56
  • 3
    That's odd. Oh - I just noticed `viewReference.window.screen` in you code. Not sure what that is about. This is the way I do it.(sry @ the formatting. Good luck!) `displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(barEvent)]; displayLink.frameInterval = 5; [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];` – spring Jan 22 '12 at 23:46
  • This works! Thank you very much! screen is the property of the storyboards view. Every text I read sent the message to the screen. – Lars Jan 24 '12 at 17:26
  • grabster, I just realized that while spacing out I edited your answer to add more info. I feel bad about this :O @NoGrabbing – Fattie Nov 18 '17 at 17:25