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 12-26-2008, 04:46 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
Default Using sections in UITableView

Can anyone point me to a tutorial or other resource on using sections in the UITableView controller. (by sections i mean the headers used for each letter in the contacts app.)

Thanks
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 12-26-2008, 05:50 PM   #2 (permalink)
New Member
 
Join Date: Dec 2008
Location: Manchester CT
Posts: 16
Default

You have to implement the TableView:titeForHeaderInSection method as in example below.

- (NSString *)tableViewUITableView *)tableView titleForHeaderInSectionNSInteger)section {

switch (section) {
case 0:
return @"A";
break;
case 1:
return @"B";
break;

case 2:
return @"C";
break;
default:
return @"D";
break;
}
}
SidScienceKid is offline   Reply With Quote
Old 12-26-2008, 06:05 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
Default

I got that bit working but now I'm having more problems. In the cellForRowAtIndexPath method I currently have:

Code:
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 
	Races *r =(Races *)[appDelegate.racesArray objectAtIndex:indexPath.row];
	
	[cell setText:r.name];
Now that I have multiple arrays to populate each section however I can't get it to work. I tried using the switch statement like before but of course the (section) part does note work because it is not declared in this method.

Any ideas?
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 12-26-2008, 07:05 PM   #4 (permalink)
New Member
 
Join Date: Dec 2008
Location: Manchester CT
Posts: 16
Default

The IndexPath variable in CellForRowAtIndex has both section and row .

You can do
switch (indexPath.section) {


}
SidScienceKid is offline   Reply With Quote
Old 12-26-2008, 07:30 PM   #5 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
Default

Ah ryt sorry

Thanks for your help
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Reply

Bookmarks

Tags
header, section, tutorial, uitableview

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: 251
18 members and 233 guests
2WeeksToGo, @sandris, AdamL, ADY, BrianSlick, Dani77, F_Bryant, GHuebner, HDshot, headkaze, mer10, prchn4christ, Rudy, smithdale87, Thompson22, timle8n1, Touchmint, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,748
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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