PDA

View Full Version : Table View Help




geiger10d
Feb 2, 2011, 11:08 AM
this is a list of table view inside of my tab bar application, i dont know how to get it to have individual cells for example if i were to click on Leg Workouts it would go to a leg workout table that says Leg Workout 01 Leg workout 02 Leg Workout 03, i want it to say something like Calf Raises, Leg Press, Box Jumping, also how do i get it to list more then 3 rows? thanks.




if ([self.title isEqualToString:@"Leg Workouts"]) {
cell.textLabel.text = [NSString stringWithFormat:@"Leg Workout%d", [indexPath indexAtPosition:1]];
cell.textLabel.text = [NSString stringWithFormat:@"Leg Workout %d", [indexPath indexAtPosition:1]];
} else if ([self.title isEqualToString:@"Ab Workouts"]) {
cell.textLabel.text = [NSString stringWithFormat:@"Ab Workout %d", [indexPath indexAtPosition:1]];
}else if ([self.title isEqualToString:@"Chest Workouts"]) {
cell.textLabel.text = [NSString stringWithFormat:@"Chest Workout %d", [indexPath indexAtPosition:1]];
}else if ([self.title isEqualToString:@"Shoulder Workouts"]) {
cell.textLabel.text = [NSString stringWithFormat:@"Shoulder Workout %d", [indexPath indexAtPosition:1]];
}else if ([self.title isEqualToString:@"Back Workouts"]) {
cell.textLabel.text = [NSString stringWithFormat:@"Back Workout %d", [indexPath indexAtPosition:1]];
}else if ([self.title isEqualToString:@"Bicep Workouts"]) {
cell.textLabel.text = [NSString stringWithFormat:@"Bicep Workout %d", [indexPath indexAtPosition:1]];
}else if ([self.title isEqualToString:@"Tricep Workouts"]) {
cell.textLabel.text = [NSString stringWithFormat:@"Tricep Workout %d", [indexPath indexAtPosition:1]];
}else if ([self.title isEqualToString:@"Miscellaneous Workouts"]) {
cell.textLabel.text = [NSString stringWithFormat:@"Miscellaneous Workout %d", [indexPath indexAtPosition:1]];

}

return cell;
}



cnstoll
Feb 2, 2011, 12:05 PM
So when you implement your table view for the list of workout types you would set up a few different methods.

There's the number of sections and number of rows methods. If you just want the types to be in one section, then just return the number of rows there (which should correspond to the number of types), and return 1 for the number of sections.

Then when your tableView is created it will call those methods first, which gets the number of cells, and then call your cellForIndexPath method for each cell. In that you get an indexPath variable. Based on the row and section of that object, you'll customize the title for the cell. If you want the first one to b e leg workouts, check if indexPath.row == 0, and set the title to @"Leg Workouts".

Similarly, you'll want to do sort of the same thing for the didSelectRowAtIndexPath method, and if the user selects the first row (indexPath.row == 0) then you'll want to present a new view with your list of leg workouts.

Hope that helps..

geiger10d
Feb 2, 2011, 02:07 PM
I'm not really understanding, can you show me whatt that would look like?

cnstoll
Feb 2, 2011, 02:16 PM
I'd just be repeating what's available in many places online.

Just google search for "UITableViewController tutorial" if what I wrote doesn't make sense.