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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 10-01-2009, 09:06 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2008
Location: Munich, Germany
Posts: 108
Default Allowing maximum number of rows in array

Hi,

in my NSMutableArray there are constantly objects added to it while the app is running.
What I want to do is, to have a maximum number of rows in that array (lets say 50). So once the array count reaces 50 I want the last row (first row added row) to be deleted. Something like in the messages app where there is only a certain numbers of rows visible.
How would I do this?
Thanks alot!
freshking is offline   Reply With Quote
Old 10-01-2009, 09:20 AM   #2 (permalink)
Registered Member
 
rwenderlich's Avatar
 
Join Date: Aug 2009
Posts: 162
Default

In the section where you're adding items onto the NSMutableArray, just check the count of the array before putting a new item onto it, and remove the oldest item first if it's at maximum length.
__________________
Check out my iPhone development blog!

Motivate yourself to become an expert with LevelMeUp!

--Ray Wenderlich
rwenderlich is offline   Reply With Quote
Old 10-01-2009, 09:36 AM   #3 (permalink)
Former NeXTStep Developer
 
Join Date: Mar 2009
Posts: 997
Default

Or, if you're adding items to the array in a lot of places, and don't want to be putting those checks everywhere, you could subclass NSMutableArray and do the check in your own insert method.

joe
FlyingDiver is offline   Reply With Quote
Old 10-01-2009, 10:04 AM   #4 (permalink)
Humbled Student
 
Dutch's Avatar
 
Join Date: Apr 2009
Location: Long Island, NY
Age: 32
Posts: 883
Send a message via AIM to Dutch
Default

Yeah if you're using an NSMutableArray, you can just do...
Code:
if ([theArray count] >=50){
    [theArray removeObjectAtIndex:49];
}
[theArray insertObject:yourObjectToInsert atIndex:0];
Dutch is offline   Reply With Quote
Old 10-01-2009, 02:16 PM   #5 (permalink)
Registered Member
 
Join Date: Oct 2008
Location: Munich, Germany
Posts: 108
Default

Thats all I wanted to know! Thanks!

@Dutch: Thanks alot. Exactly what I needed!
freshking is offline   Reply With Quote
Old 10-01-2009, 02:29 PM   #6 (permalink)
Humbled Student
 
Dutch's Avatar
 
Join Date: Apr 2009
Location: Long Island, NY
Age: 32
Posts: 883
Send a message via AIM to Dutch
Default

Glad to help.
Dutch is offline   Reply With Quote
Reply

Bookmarks

Tags
count, delete, nsmutablearray, rows

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: 345
19 members and 326 guests
ADY, Dani77, Duncan C, F_Bryant, Grinarn, HemiMG, Herbie, jansan, JasonR, linkmx, macquitzon216, mer10, Monstertaco, prchn4christ, Robiwan, sly24, Touchmint, twerner, zulfishah
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,760
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

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