[ASK]Complex Multiple XIB

Discussion in 'iOS Development' started by 0r4ngB41k, Nov 18, 2009.

  1. 0r4ngB41k

    0r4ngB41k New Member

    Joined:
    Nov 9, 2009
    Messages:
    7
    Likes Received:
    0
    Device:
    iPod touch
    I'm making a multi-user application. where every user has his own page. I have made this application from the login page and enter the user page.

    (Case 1) But I have some constraints such as the login page, where the pages are not displayed full-screen (see picture)

    Please Register or Log in to view images


    By or4ngb41k at 2009-11-18
    my code to load loginViewController.xib
    [OBJC]// load login page
    loginViewController *aViewController = [[loginViewController alloc] initWithNibName

    Please Register or Log in to view images

    "loginViewController" bundle:[NSBundle mainBundle]];
    [self set_loginViewController:aViewController];
    [aViewController release];

    UIView *controllersView = [_loginViewController view];
    [window addSubview:controllersView];
    [window makeKeyAndVisible];[/OBJC]
    Question: How to make loginViewController full screen (like picture)?

    (case 2)
    For now, i have 3 XIB
    1. mainwindow.xib (tabBarAppDelegate.h/.m)
    2. loginViewController.xib (loginViewController.h/.m)
    3. groupAViewController.xib (groupAViewController.h/.m)

    but its future will have many XIB for each user group (see picture)

    Please Register or Log in to view images


    By or4ngb41k at 2009-11-18

    When the application finish launching
    [OBJC]- (void)applicationDidFinishLaunching

    Please Register or Log in to view images

    UIApplication *)application {
    self._server_url = @"http://localhost/m3class_iphone/index.php";

    // load login page
    loginViewController *aViewController = [[loginViewController alloc] initWithNibName

    Please Register or Log in to view images

    "loginViewController" bundle:[NSBundle mainBundle]];
    [self set_loginViewController:aViewController];
    [aViewController release];

    UIView *controllersView = [_loginViewController view];
    [window addSubview:controllersView];
    [window makeKeyAndVisible];
    }
    [/OBJC]

    User login to server
    [OBJC]- (void)connectionDidFinishLoading

    Please Register or Log in to view images

    NSURLConnection *)connection {
    NSString *responseString = [[NSString alloc] initWithData:_receivedData encoding:NSUTF8StringEncoding];

    NSString *jsonString = [NSString stringWithString:responseString];
    NSDictionary *dictionary = [jsonString JSONValue];
    NSString *status = [dictionary objectForKey

    Please Register or Log in to view images

    "success"];

    if ([status integerValue] == YES)
    {
    // first hide login page
    [[tabbarAppDelegate shareAppDelegate] showTabBar];
    else
    {
    [self showAlert

    Please Register or Log in to view images

    "Username or password invalid" message:nil];
    }

    [connection release];
    [_receivedData release];
    } [/OBJC]

    tabBarAppDelegate.h/.m
    [OBJC]-(void)showTabBar{
    [window addSubview:tabBarController.view];
    }
    [/OBJC]

    And in this tabbarcontroller I load XIB file in accordance with the user group.

    question: How to load XIB accordance with user groups?

    please advice.
    Before and after I say thank you very much.

    regards,
    Budi
  2. Collateral

    Collateral Active Member

    Joined:
    Sep 23, 2007
    Messages:
    1,974
    Likes Received:
    6
    Device:
    iPhone 3GS (Black)
    Why would you use so many XIB's? Why not make a few XIB's and change what they contain based on the group, etc.?
  3. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Somewhere global:
    [OBJC]enum {UserGroup1, UserGroup2, etc} UserGroup;[/OBJC]

    Later in your code:
    [OBJC]
    switch(userGroup) {
    case UserGroup1: [self presentParentXIB1]; break;
    case UserGroup1: [self presentParentXIB2]; break;
    etc...
    default: [self presentDefaultXIB]; break;
    }
    [/OBJC]

    Each parent xib will have its own source code attached to it, meaning that each parent xib will have connections to its own child xibs, and none else. You only really have to detect the user group once and select the correct parent. The rest is child's play, so to speak.
  4. 0r4ngB41k

    0r4ngB41k New Member

    Joined:
    Nov 9, 2009
    Messages:
    7
    Likes Received:
    0
    Device:
    iPod touch
    sorry, I am a newcomer to the iphone programmer. so I do not know how to make effective applications.

    I know right now is for every different page, I create a new XIB.

    This is my first project. I am very grateful, if you can tell the best solution, how do I make an application to many user groups.

    eg I have 3 user groups.
    1. Group A -> groupAViewController.xib
    children:
    - Child 1 -> groupAChild1ViewController.xib
    - Child 2 -> groupAChild2ViewController.xib
    - Other ....

    2. Group B -> groupBViewController.xib
    children:
    - Child 1 -> groupBChild1ViewController.xib
    - Child 2 -> groupBChild2ViewController.xib
    - Other ....

    3. Group C -> groupCViewController.xib
    children:
    - Child 1 -> groupCChild1ViewController.xib
    - Child 2 -> groupCChild2ViewController.xib
    Group C -> groupCViewController.xib

    Is this about the code should I make?

    [OBJC]
    enum {GroupA, GroupB, GroupC} UserGroup;
    [/OBJC]

    [OBJC]
    switch(userGroup) {
    case GroupA: [self presentParentGroupA]; break;
    case GroupB: [self presentParentGroupB]; break;
    case GroupC: [self presentParentGroupC]; break;
    default: [self presentDefaultXIB]; break;
    }
    [/OBJC]

    example code for presentParentGroupA, presentParentGroupB or presentParentGroupC
    [OBJC]
    -(void)presentParentGroupA
    {
    groupAViewController *aViewController = [[groupAViewController alloc] initWithNibName

    Please Register or Log in to view images

    "groupAViewController" bundle:[NSBundle mainBundle]];
    [self set_groupAViewController:aViewController];
    [aViewController release];

    UIView *controllersView = [_groupAViewController view];
    return controllersView;
    //[window addSubview:controllersView];
    //[window makeKeyAndVisible];
    }
    [/OBJC]

    Please advice

    Please Register or Log in to view images



    btw, please advice for case 1

    Please Register or Log in to view images




    Thanks & regards,
    Budi
  5. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    Instead of that, you should make some IB connections to change the content of one NIB, instead of making 3.

    Read Skylar's IB tutorials, they could help you.

Share This Page