04-03-2011, 11:46 AM
#1 (permalink )
Registered Member
Join Date: Mar 2011
Posts: 10
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."?
04-03-2011, 11:56 AM
#2 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
I don't understand the question, but see the table view link in my signature.
04-03-2011, 12:09 PM
#3 (permalink )
Registered Member
Join Date: Mar 2011
Posts: 10
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?
04-03-2011, 12:16 PM
#4 (permalink )
Emphasizing Fundamentals
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
So, yes, see the table view link in my signature.
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» 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