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 04-03-2011, 11:46 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 10
TechnicalNerd is on a distinguished road
Default UITableView Sections Help

Hi everyone. I'm using this code to display a UITable View

Code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	
	
	return [taskNames count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    
    if(section == 0)
        return @"Lists";
    if(section == 1)
        return @"Personal To Do's";
    if(section ==2)
        return @"School Assignments";
    else
        return @"Work Assignments";
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"] autorelease];
    }
	
	cell.textLabel.text = [taskNames objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = [taskDues objectAtIndex:indexPath.row];
    
    if (cell.detailTextLabel.text == @"March 21, 2011") {
        cell.detailTextLabel.textColor = [UIColor redColor];
    }
	
	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    [[cell imageView] setImage:[UIImage imageNamed:[toDoTypeOptionImages objectAtIndex:indexPath.row]]];
	
	return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ListViewViewController *listView = [[ListViewViewController alloc]init];
    PersonalViewViewController *personalView = [[PersonalViewViewController alloc]init];
    SchoolViewViewController *schoolView = [[SchoolViewViewController alloc]init];
    WorkViewViewController *workView = [[WorkViewViewController alloc]init];
    
    if ([tableView cellForRowAtIndexPath:indexPath].textLabel.text == @"Get Grocerys") {
        [self.navigationController pushViewController:listView animated:YES];
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        listView.title = @"View Task";
        listView.name.text = [tableView cellForRowAtIndexPath:indexPath].textLabel.text;
        listView.due.text = [tableView cellForRowAtIndexPath:indexPath].detailTextLabel.text;
        listView.due.textColor = [UIColor redColor];
    }
    if ([tableView cellForRowAtIndexPath:indexPath].textLabel.text == @"Do Laundry") {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
        [dateFormatter setTimeStyle:NSDateFormatterNoStyle];
        
        NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:162000];
        
        NSString *formattedDateString = [dateFormatter stringFromDate:date];
        
        [self.navigationController pushViewController:personalView animated:YES];
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        personalView.title = @"View Task";
        personalView.name.text = [tableView cellForRowAtIndexPath:indexPath].textLabel.text;
        //personalView.due.text = [tableView cellForRowAtIndexPath:indexPath].detailTextLabel.text;
        personalView.due.text = formattedDateString;
    }
    if ([tableView cellForRowAtIndexPath:indexPath].textLabel.text == @"Read Pages 92-95") {
        [self.navigationController pushViewController:schoolView animated:YES];
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        schoolView.title = @"View Task";
        schoolView.name.text = [tableView cellForRowAtIndexPath:indexPath].textLabel.text;
        schoolView.due.text = [tableView cellForRowAtIndexPath:indexPath].detailTextLabel.text;
    }
    if ([tableView cellForRowAtIndexPath:indexPath].textLabel.text == @"Meeting") {
        [self.navigationController pushViewController:workView animated:YES];
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        workView.title = @"View Task";
        workView.name.text = [tableView cellForRowAtIndexPath:indexPath].textLabel.text;
        workView.due.text = [tableView cellForRowAtIndexPath:indexPath].detailTextLabel.text;
    }
    
	[listView release];
    [personalView release];
    [schoolView release];
    [workView release];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
	
    taskNames = [[NSMutableArray alloc]init];
    taskDues = [[NSMutableArray alloc]init];
    toDoTypeOptionImages = [[NSMutableArray alloc]init];
    lsNames = [[NSMutableArray alloc]init];
    lsDues = [[NSMutableArray alloc]init];
    ptdNames = [[NSMutableArray alloc]init];
    ptdDues = [[NSMutableArray alloc]init];
    saNames = [[NSMutableArray alloc]init];
    saDues = [[NSMutableArray alloc]init];
    waNames = [[NSMutableArray alloc]init];
    waDues = [[NSMutableArray alloc]init];
    
    [taskNames addObject:@"Get Grocerys"];
    [taskNames addObject:@"Do Laundry"];
    [taskNames addObject:@"Read Pages 92-95"];
    [taskNames addObject:@"Meeting"];
    
    [taskDues addObject:@"March 20, 2011"];
    [taskDues addObject:@"April 12, 2011"];
    [taskDues addObject:@"March 18, 2011"];
    [taskDues addObject:@"May 2, 2011"];
    
    [toDoTypeOptionImages addObject:@"179-notepad.png"];
    [toDoTypeOptionImages addObject:@"111-user.png"];
    [toDoTypeOptionImages addObject:@"96-book.png"];
    [toDoTypeOptionImages addObject:@"178-city.png"];
    
    [lsNames addObject:@"Get Grocerys"];
    
    [lsDues addObject:@"March 20, 2011"];
    
    [ptdNames addObject:@"Do Laundry"];
    
    [ptdDues addObject:@"April 12, 2011"];
    
    [saNames addObject:@"Read Pages 92-95"];
    
    [saDues addObject:@"March 18, 2011"];
    
    [waNames addObject:@"Meeting"];
    
    [waDues addObject:@"May 2, 2011"];

    
    [[UIApplication sharedApplication]setApplicationIconBadgeNumber:[taskNames count]];
}
I was wondering, how would I say, "section 1's items are what's in lsNames, sections 2's items are what's in ptdNames, etc."?
TechnicalNerd is offline   Reply With Quote
Old 04-03-2011, 11:56 AM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

I don't understand the question, but see the table view link in my signature.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

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

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 04-03-2011, 12:09 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 10
TechnicalNerd is on a distinguished road
Default

I mean, right now when I run the application, the content of taskNames/taskDues populates each section of the UITableView, and each section is identical. I want to know how to make it so that The first section contains the content of lsNames/lsDues, the second section contains the content of ptdNames/ptdDues, the third section contains the content of saNames/saDues and finally the fourth section contains the content of waNames/waDues. How would I do that?
TechnicalNerd is offline   Reply With Quote
Old 04-03-2011, 12:16 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

So, yes, see the table view link in my signature.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

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

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Reply

Bookmarks

Tags
ios, sections, 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: 371
12 members and 359 guests
condor304, dansparrow, dre, ilmman, LezB44, michelle, Objective Zero, samdanielblr, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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