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 01-11-2010, 08:11 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 102
Default tableView sections with data from a single array object

Hi guys,

I've got a situation, where i have to add sections to a tableview.
An NSMutableArray is having objects with anNSInteger Type and NSString title.


Code:
ExOb *eob = (ExOb *)[appDelegate.ExArray objectAtIndex:indexPath.row];
want i want to do is,
if (eob.Type == 1){
//add to indexpath.section 1
} else if (eob.Type == 2){
//add to section 2
}
else if (eob.Type == 1){
//add to section 3
}

however, i can actually implement this cuz i simply dont kno how to.
and also, to return the exact number of rows where eob.type==1.. etc

Most examples have arrays for each sections.

any suggestions would be great
raheel is offline   Reply With Quote
Old 01-11-2010, 08:36 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,072
Default

There is a reason most examples do that. Is there a reason that you can't?
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 01-11-2010, 08:42 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 102
Default

no reason actually. I'd hav to initialise about 4 arrays in viewdidload, add them to dictionary. and then add all those to a single array.

I was just thinking if theres an easier way, the data is huge, many cells. I was looking for a memory saving way out
raheel is offline   Reply With Quote
Old 01-11-2010, 08:49 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,072
Default

You'd have the same amount of data either way, right? The memory for the containers themselves would be relatively small.

I guess it depends on how you define "easier". I personally keep a master list of data, and then have a sorting routine that breaks it down into smaller parts. My table view methods only care about the smaller parts; they don't care how the data was sorted.

Here is something that should help:
Clinging To Ideas: Taming Table Views

After I wrote that, I learned that CoreData has a NSFetchedResultsSectionInfo class which is basically the same thing, so I think I'm on the right track.

And you only "need" 2 arrays: master and sorted.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 11-29-2010, 05:00 AM   #5 (permalink)
Registered Member
 
Join Date: Nov 2010
Location: Calabasas, Ca
Posts: 22
Default

Quote:
Originally Posted by raheel View Post
Hi guys,

I've got a situation, where i have to add sections to a tableview.
An NSMutableArray is having objects with anNSInteger Type and NSString title.


Code:
ExOb *eob = (ExOb *)[appDelegate.ExArray objectAtIndex:indexPath.row];
want i want to do is,
if (eob.Type == 1){
//add to indexpath.section 1
} else if (eob.Type == 2){
//add to section 2
}
else if (eob.Type == 1){
//add to section 3
}

however, i can actually implement this cuz i simply dont kno how to.
and also, to return the exact number of rows where eob.type==1.. etc

Most examples have arrays for each sections.

any suggestions would be great

I had done something similar before and a quick test shows that it should work for you.

In the :
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
you need to create a new index like this:

Code:
int matchingIndex = ((indexPath.section *2)+ indexPath.row);
This tracks with a group of 2 rows per section. If your sections have a different number of rows then adjust the multiplier for that.

Of course if your sections have varying row counts the math doesn't work. It worked for me.

Deanne
deannerene is offline   Reply With Quote
Reply

Bookmarks

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: 424
13 members and 411 guests
bev6a8hl, beyondstop, Edsilmars, HowEver, Hyde, john234ny, linkmx, MozyMac, phillipie99, pill5b3rry, pochuang, pufftissue, Rudy
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 157,847
Threads: 88,913
Posts: 379,291
Top Poster: BrianSlick (7,072)
Welcome to our newest member, bev6a8hl
Powered by vBadvanced CMPS v3.1.0

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