UITableView issue

Discussion in 'iPhone/iPad Programming' started by GhostDZ9, May 18, 2011.

  1. GhostDZ9, May 18, 2011
    Last edited by a moderator: May 18, 2011

    macrumors regular

    Joined:
    Sep 13, 2010
    #1
    Hey guys,

    So im creating a TableView and I want to know how to programmatically change the style from single to grouped?

    Regards,

    Ghost

    EDIT:

    Nevermind i figured it out, however if people are wondering what i was wondering it is
    Code:
    - (id)initWithStyle: (UITableViewStyle)style {
    if (self = [super initWithStyle:UITableViewStyleGrouped]) {
    }
    return self;
    }
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    You sure you wanna ignore initWithStyle:'s style parameter value? Why not just change the call to initWithStyle: to something like:
    Code:
    [tableView initWithStyle:UITableViewStyleGrouped];
     
  3. thread starter macrumors regular

    Joined:
    Sep 13, 2010
    #3
    And where abouts would I put that piece of code?
     
  4. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    Actually I would change it this way

    Code:
    // MyViewController
    - (id)init {
         if ((self = [super initWithStyle:UITableViewStyleGrouped])) 
         {
         }
         return self;
    }
    
    // Creation
    MyViewController* controller = [[MyViewController alloc] init];
     
  5. thread starter macrumors regular

    Joined:
    Sep 13, 2010
    #5
    What difference would that make?
     
  6. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    Having a parameter that your code ignores, as you show, doesn't make much sense. I always like my view controllers to keep the name of their nib private and the style in this case doesn't need to be known by other classes.

    The way you show will work correctly.
     

Share This Page