Table View Help

Discussion in 'iOS Programming' started by geiger10d, Feb 2, 2011.

  1. geiger10d, Feb 2, 2011
    Last edited by a moderator: Feb 2, 2011

    geiger10d macrumors member

    Jan 31, 2011
    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;
  2. cnstoll macrumors 6502

    Aug 29, 2010
    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..
  3. geiger10d thread starter macrumors member

    Jan 31, 2011

    I'm not really understanding, can you show me whatt that would look like?
  4. cnstoll macrumors 6502

    Aug 29, 2010
    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.

Share This Page