detail text label in a table view help

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

  1. geiger10d macrumors member

    Joined:
    Jan 31, 2011
    #1
    hi im making a table view and i was wondering how to put a description of the table cell name directly under it and im not sure how to do that.

    so something like this


    (table cell)
    BENCH PRESS
    this exercise works your chest

    etc
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    You can UITableViewCellStyleSubtitle for this. cell.textLabel.text is the title and cell.detailTextLabel.text is the subtitle in grey.

    If this isn't what you want then you'll need to use a custom table view cell. You can look at the TableViewSuite sample code for examples of how to do that.
     
  3. geiger10d, Feb 19, 2011
    Last edited by a moderator: Feb 19, 2011

    geiger10d thread starter macrumors member

    Joined:
    Jan 31, 2011
    #3
    Code:
    	if ([self.title isEqualToString:@"Chest Workouts"]) {
    		switch (row) {
    			case 0:
    				cell.textLabel.text = @"Bench Press";
    				cell.detailTextLabel.text = [NSString stringWithString:@"These are bench presses."];
    				cell.textLabel.font = [UIFont systemFontOfSize:14]; //Change this value to adjust size
    				cell.textLabel.numberOfLines = 2; //Change this value to show more or less lines.
    				break;
    
    it still doesnt work
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Did you remember to set the UITableViewCellStyle?
     
  5. geiger10d thread starter macrumors member

    Joined:
    Jan 31, 2011
    #5
    how would i go about that?
     
  6. dejo, Feb 19, 2011
    Last edited: Feb 19, 2011

    dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    You probably are already calling initWithStyle:reuseIdentifier: within your tableView:cellForRowAtIndexPath: method. That's where you would change it.

    P.S. Have you read through the entire Table View Programming Guide for iOS yet?
     
  7. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #7
    I think that you can't get multiline labels using the default table view cells. If you need that there's more that needs to be done and you need to use custom cells.
     
  8. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #8
    what this guy needs to do is just read the UITableView documentation, but probably is too lazy. So will post a snippet..

    Code:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        
        static NSString *CellIdentifier = @"Cell";
    	
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:[B]UITableViewCellStyleValue1[/B] reuseIdentifier:CellIdentifier] autorelease];
        }
       
    	cell.textLabel.text = @"Whatever u want";
    	cell.detailTextLabel.text = @"Detail whatever u want";
    	return cell;
    }
    
    They already told u to do this..
    U can change the BOLD thing into others, which u have to change to ur likings, or just look for CustomTableViewCell..
     
  9. geiger10d thread starter macrumors member

    Joined:
    Jan 31, 2011
    #9
    thanks man i got it, and i changed it to subtitle, no i did read the documentation i knew i needed the subtitle but i just didnt know where to put it... but thanks for telling me where to change it!
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    Listing 5-1 of that document shows you exactly where to put it.
     
  11. geiger10d thread starter macrumors member

    Joined:
    Jan 31, 2011
    #11
    hey Andrei Kirilenko ( who you look like) just because i said i did not read it before does not mean I would never read it... There really is no need for you to comment on this thread just to tell me that you did tell me where to put something... My bad i missed something... Not really cool to try to make me feel like a idiot

    this guy just was more clear...
    ;)
     
  12. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    I'm confused. I thought you said you had read it.

    I did not intend to make you feel like an idiot. I apologize if that's how it came across. I just wanted to point to specifically where the guide I directed you to helped you with your specific issue. I meant no harm.

    If by "this guy" you meant "jnoxx" and all you are seeking from this forum is code you can copy-and-paste, then I will have to bow out of helping you in the future. Copy-and-paste is not programming. Good luck, though.
     
  13. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #13
    Thanks for not putting me in a box oh godly moderator *bows down*
    And yea, I shouldn't have done that.. But I remember the times when I began, I adored people like well, myself, who gave me snippets of code to go with.
    So I have mixed feelings of how to handle these "situations" (omg i'm typing like this is a hostage situation).
    So well. Thanks anyways, and i'd advise to stop bothering so much ;)
     
  14. geiger10d thread starter macrumors member

    Joined:
    Jan 31, 2011
    #14
    no man i was not just looking to copy and paste i was looking for where the command was to change it.... i would love for you NOT to "bow out of helping me in the future" we just had a miscommunication that is all.
     

Share This Page