Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Poy77

macrumors newbie
Original poster
Sep 5, 2010
18
0
I am using Timer to get alarm after a while and I took example from apple source code:
Code:
CADisplayLink *aDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawFrame)];
        [aDisplayLink setFrameInterval:animationFrameInterval];
        [aDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
        self.displayLink = aDisplayLink;

It is working, but I a got warning:
displayLinkWithTarget:selector method not found.

Also if I set lock screen, the timer won't work. What I should use instead of it?
 
Last edited by a moderator:
I am using Timer to get alarm after a while and I took example from apple source code:
CADisplayLink *aDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:mad:selector(drawFrame)];
[aDisplayLink setFrameInterval:animationFrameInterval];
[aDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
self.displayLink = aDisplayLink;

It is working, but I a got warning:
displayLinkWithTarget:selector method not found.

Also if I set lock screen, the timer won't work. What I should use instead of it?

Do you have a drawFrame method?
 
Do you have a drawFrame method?
No, I use my own (previous was just copied from apple code):
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:mad:selector(decreaseTimer:)];

And I have decreaseTimer method.

Why timer doesn't work while iphone is inactive?
 
No, I use my own (previous was just copied from apple code):
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:mad:selector(decreaseTimer:)];

And I have decreaseTimer method.

You get a warning on that code because you're using NSClassFromString(). That means the compiler can't tell what the actual class will be at runtime, so it can't tell whether it has the given method or not.

Is there some reason you're using NSClassFromString()? It seems like an odd thing to do. If you require the CADisplayLink class anyway, you should include its header.


Why timer doesn't work while iphone is inactive?
Do you understand what CADisplayLink is for? It's for refreshing the screen when some part of your content needs to be redrawn. If the phone is inactive or locked, then your content isn't showing, so logically, none of your content needs redrawing.

Please describe exactly what you're trying to accomplish. If you're just doing a timer, then see the NSTimer class. CADisplayLink is only for timed screen redrawing.
 
Do you understand what CADisplayLink is for? It's for refreshing the screen when some part of your content needs to be redrawn. If the phone is inactive or locked, then your content isn't showing, so logically, none of your content needs redrawing.

Please describe exactly what you're trying to accomplish. If you're just doing a timer, then see the NSTimer class. CADisplayLink is only for timed screen redrawing.
It is countdown counter. Second by second it shows a new value and in zero it will play an audio file.
---
Code:
// Timer event is called whenever the timer fires
- (void)decreaseTimer:(id)sender
{
    ...
    /* Update timer count */
    timerCount--;
/* Calculate new digits */
        newSecondsHighDigit = (timerCount%60)/10;
        newSecondsLowDigit = (timerCount%60)%10;
        newMinutesDigit = timerCount/60;
    
        if(newSecondsLowDigit != oldSecondsLowDigit)
        {
            [displayLowDigit setNewDisplayNumber:newSecondsLowDigit];
        }
        if(newSecondsHighDigit != oldSecondsHighDigit)
        {
            [displayHighDigit setNewDisplayNumber:newSecondsHighDigit];
        }
        if(newMinutesDigit != oldMinutesDigit)
        {
            [displayMinuteDigit setNewDisplayNumber:newMinutesDigit];
        }
   ...
}
---

---    
    displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(decreaseTimer:)];
    [displayLink setFrameInterval:60];
    [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
---

I have implemented custom numbers of 7-segment display. I use CGContextSetRGBFillColor function to draw a new number in 7-segment display. 7-segment display is own class. Would it be better to use NSTimer in my case?

Display:
http://dl.dropbox.com/u/25577/ObjectiveC/Screen shot 2011-06-12 at 22.26.33.png
Warnings:
http://dl.dropbox.com/u/25577/ObjectiveC/Screen shot 2011-06-12 at 22.16.15.png
 
Last edited by a moderator:
Would it be better to use NSTimer in my case?

Yes.


And you still haven't given any reason why you're using a CADisplayLink like this:
Code:
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(decreaseTimer:)];
instead of like this:
Code:
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(decreaseTimer:)];
It's a weird way to use a class, and it wasn't used that way in the original Apple example you started from, according to your original post.

If you don't understand when to use NSClassFromString() or why, then you won't understand why you're getting the warnings. After you improve your understanding, the way to remove the warnings should become clear.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.