Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-20-2011, 02:59 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2011
Location: New Zealand
Posts: 7
ethorneloe is on a distinguished road
Default Question about displaying views

Hi,

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.

thanks
ethorneloe is offline   Reply With Quote
Old 06-20-2011, 03:15 AM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

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.
Domele is offline   Reply With Quote
Old 06-20-2011, 03:59 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2011
Location: New Zealand
Posts: 7
ethorneloe is on a distinguished road
Default

Hey thanks for the quick reply.

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?
ethorneloe is offline   Reply With Quote
Old 06-20-2011, 04:12 AM   #4 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

you can start using google....

http://www.iphonedevsdk.com/forum/ip...n-ios-app.html
__________________
dany_dev is offline   Reply With Quote
Old 06-20-2011, 04:28 AM   #5 (permalink)
Registered Member
 
Join Date: Jun 2011
Location: New Zealand
Posts: 7
ethorneloe is on a distinguished road
Default

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.
ethorneloe is offline   Reply With Quote
Old 06-20-2011, 04:36 AM   #6 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

you said
Quote:
Originally Posted by ethorneloe View Post
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?
__________________

Last edited by dany_dev; 06-20-2011 at 04:42 AM.
dany_dev is offline   Reply With Quote
Old 06-20-2011, 05:32 AM   #7 (permalink)
Registered Member
 
Join Date: Jun 2011
Location: New Zealand
Posts: 7
ethorneloe is on a distinguished road
Default

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.

thanks again Domele for your idea.
ethorneloe is offline   Reply With Quote
Reply

Bookmarks

Tags
image, uiview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 326
8 members and 318 guests
chemistry, Dnnake, iOS.Lover, lendo, leostc, Leslie80, pbart, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:25 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0