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

tacotester1

macrumors member
Original poster
Dec 19, 2013
99
0
Does anyone have any good tutorials or references to build arrays with uiimages
I have read the Apple docs but I can't seem to figure out where to implement.
The docs tell me all the the class methods, primitives etc.
but I am looking information on implementing and why.

I am new and am just trying to find a good place to start.
I have done a couple tutorials on arrays through the NSLOG
but am lost when it comes to the implementing and connecting not through the debugger

if this is the supidest question u have ever seen.
forgive me
thanks
 
If you are just learning, I recommend you get a book. There are plenty of threads here recommending books.

You could also Google: nsmutablearray tutorial
That brings up plenty of hits.

If you have something specific in mind then you need to describe it well.

Placing a bunch of images into an array likely isn't a good thing to do because you may run out of memory. You should only load what you need to use or display and perhaps a few more.
 
There is an Apple tutorial project on Lazy loading of images to be displayed in a Tableview.

If you can find that in the Doc's it might kick you in the right direction for a few things your trying to do.
 
Does anyone have any good tutorials or references to build arrays with uiimages

Where do you want to use those UIImages? Tables (where lazy loading should be preferred to conserve memory / initial display of the list itself), or, the problems (memory usage and fetch time, particularly when done via the Net) with immediate image fetching aren't a problem?

If the latter, what you need to do is really simple. An example:
Code:
NSMutableArray* arr = [NSMutableArray array];

 for (int i=0; i < photosCnt; i++)
    {
// set up "fullUrlOfCurrPhoto"
        UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:fullUrlOfCurrPhoto]]];
        [arr addObject:image];
        }

If you need lazy loading, make absolutely sure you check out https://developer.apple.com/library/ios/samplecode/lazytableimages/introduction/intro.html . It's a very nice example of lazy image loading.
 
Where do you want to use those UIImages? Tables (where lazy loading should be preferred to conserve memory / initial display of the list itself), or, the problems (memory usage and fetch time, particularly when done via the Net) with immediate image fetching aren't a problem?

If the latter, what you need to do is really simple. An example:
Code:
NSMutableArray* arr = [NSMutableArray array];

 for (int i=0; i < photosCnt; i++)
    {
// set up "fullUrlOfCurrPhoto"
        UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:fullUrlOfCurrPhoto]]];
        [arr addObject:image];
        }

If you need lazy loading, make absolutely sure you check out https://developer.apple.com/library/ios/samplecode/lazytableimages/introduction/intro.html . It's a very nice example of lazy image loading.

thats really cool!

I will check this out.

it looks like it loads images from a remote host? or url?

so this seems to be the better way to have a bunch of images in your app. vs loading them in the xcode project supporting files?

Thanks again for your help i will research all i can on "lazy tables" you sent. I appreciate it!

----------

If you are just learning, I recommend you get a book. There are plenty of threads here recommending books.

You could also Google: nsmutablearray tutorial
That brings up plenty of hits.

If you have something specific in mind then you need to describe it well.

Placing a bunch of images into an array likely isn't a good thing to do because you may run out of memory. You should only load what you need to use or display and perhaps a few more.

great thanks
i have a couple books i have read
i just am new to it all and couldnt find any good examples that take it from nslog to images in actual app when building. maybe because it is not right solution.

I will try and find some better tutorials.

im basically making a corkboard you can put png letters on from a scroll menu on bottom of screen. i need to be able to make instances and copies of the images for words with doubles of the same letters and will need to be able to remove last touched and be able to know which is selected at the time.

so i was reading and i thought nsmutable array seemed like the way to go to make an image library u can pull from but i got stuck. thanks again for ur advice. I will definitely read up more on memory. as well. thanks!

----------

There is an Apple tutorial project on Lazy loading of images to be displayed in a Tableview.

If you can find that in the Doc's it might kick you in the right direction for a few things your trying to do.

awesome thanks!
 
thats really cool!

I will check this out.

it looks like it loads images from a remote host? or url?

so this seems to be the better way to have a bunch of images in your app. vs loading them in the xcode project supporting files?

Thanks again for your help i will research all i can on "lazy tables" you sent. I appreciate it!

1. The code I've shown should only(!) be used when you quickly prototype your stuff. For example, when developing my Foursquare client where I displayed a list of venues: an image (if present), along with the name of the venue, at first, I haven't implemented fine-tuned lazy loading for the list but just fetched the images before displaying the list. It's sufficient for a quick prototype - to just show your customers how the final app interface will look like. However, it's definitely not to be used in a production app for the following reasons:

- memory usage. If you store, say, 50 images of resolution 400*300, you can quickly allocate only for these images of 80 Mbytes of memory. On older devices (particularly if you, like me, still strive for compatibility with even the latest devices like the iPhone 3G), this can easily result in crashes or, at least, your app to be unloaded when you background it and start something else. (Assuming you don't deallocate these kinds of arrays upon sensing a backgrounding request, of course.)

- time needed for fetching, which, if you use synchronous loading, may result in having to wait for even 5-10 seconds for some images to load.

2. the code above fetches images from a remote host. Of course, whenever possible, try storing your images locally, in the app bundle, to avoid problems associated with remote fetching. This, obviously, is not the way to go if you need to access arbitrary data (e.g., Foursquare venue pics).
 
1. The code I've shown should only(!) be used when you quickly prototype your stuff. For example, when developing my Foursquare client where I displayed a list of venues: an image (if present), along with the name of the venue, at first, I haven't implemented fine-tuned lazy loading for the list but just fetched the images before displaying the list. It's sufficient for a quick prototype - to just show your customers how the final app interface will look like. However, it's definitely not to be used in a production app for the following reasons:

- memory usage. If you store, say, 50 images of resolution 400*300, you can quickly allocate only for these images of 80 Mbytes of memory. On older devices (particularly if you, like me, still strive for compatibility with even the latest devices like the iPhone 3G), this can easily result in crashes or, at least, your app to be unloaded when you background it and start something else. (Assuming you don't deallocate these kinds of arrays upon sensing a backgrounding request, of course.)

- time needed for fetching, which, if you use synchronous loading, may result in having to wait for even 5-10 seconds for some images to load.

2. the code above fetches images from a remote host. Of course, whenever possible, try storing your images locally, in the app bundle, to avoid problems associated with remote fetching. This, obviously, is not the way to go if you need to access arbitrary data (e.g., Foursquare venue pics).


great thanks! i was trying to store about 40 images + in xcode project locally. I will definitely read up on lazy tables because i had not come across that and sounds cool and interesting.
thanks alot!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.