I have a UIView subclass that implements a drawrect method to place an image on the screen. In my didFinishLaunchingWithOptions, I can create an instance of this object and get it to display the image once, but for some reason if I create a loop to do this, the image doesn't get displayed at all.
I need to be able to trigger the display of this image multiple times, so I'm wondering what I must do to enable this. Each call to the method performs some random operations to the image so I can't just perform the exact same animation multiple times.
This will display the image once:
[myObject displayImage];
This will not display the image at all:
for (int i = 0; i < 10; i++)
{
sleep(2);
[myObject displayImage];
}
Any ideas why the loop doesn't display the image? The method makes use of an animation with opacity, so the idea is that the loop will animate the image 10 times.
Would't use sleep. I believe that would make your app come to halting stop. Use an int variable and an NSTimer. Link the NSTimer to a method that does what you want and ups the int variable by one everytime. Then after you have upped the variable by one, check if it equal 10, if so invalidate the timer. Let me see the displayMessage method.
I was just reading about something called the run loop. Looks like setNeedsDisplay doesn't get dealt with until all of your other code has finished running. I can see now that my view gets displayed at the end of the loop only once. Guess my test with the loop will never work by design. Is that correct?
I have never used an NSTimer, still very much an iOS newbie. When you say link the NSTimer to a method does that mean I create some other method like [myObject test] that uses the timer and then runs setNeedsDisplay every 2 seconds for 10 iterations?
Ya I could, and so could everyone...in fact why even ask questions here?
Have spent the past 4 hours since I got back from work on google/ebooks/trying things with my code. Someone nice answered my post so I politely asked for some more details. I don't expect an answer, that is up to them.
Thanks for posting that link, but this google comment was a bit uncalled for.
I have never used an NSTimer, still very much an iOS newbie.
so if you never used NSTimer AT LEAST before ask try to use google or apple documentation...what's the problem? or you expect that every newbye should ask the code to use a NSTimer w\o searching hisself?
I don't expect anything mate. Certainly don't expect people to reply if they don't want to and I don't expect people to answer every question that some newbie asks either. But common bro, telling someone to use google is a bit of a stink comment. Obviously you posted because you wanted to help, which is great and I appreciate it, but why help and be patronizing at the same time. Anyway, thanks again for pointing me to your other post. I'll keep researching and learning from that and the documentation.