How to write it without "@"

Discussion in 'iPhone/iPad Programming' started by JacekK, Jan 21, 2013.

  1. macrumors newbie

    Joined:
    Jan 21, 2013
    #1
    I have a code lie this:

    Code:
        // Initialize List View Controller
        MTListViewController *listViewController = [[MTListViewController alloc] init];
        // Initialize Navigation Controller
        UINavigationController *listNavigationController = [[UINavigationController alloc] initWithRootViewController:listViewController];
        // Initialize Tab Bar Controller
        UITabBarController *tabBarController = [[UITabBarController alloc] init];
        // Configure Tab Bar Controller
        [tabBarController setViewControllers:@[listNavigationController]];
    its code from tutorial i am doing right now, i have old version of xcode (4.2) and this is not working:

    Code:
    [tabBarController setViewControllers:@[listNavigationController]]
    How can i write it without using "@"
     
  2. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    The @ signifies an Obj-C literal. In this case, what you specifically want is an NSArray literal.

    To get this same NSArray as a non-literal, you can do:

    Code:
    NSArray *navigationControllerArray = [NSArray arrayWithObject:listNavigationController];
    [tabBarController setViewControllers:navigationControllerArray animated:NO];
    Also, note that there isn't a method for UITabBarController called setViewControllers:, it's called setViewControllers:animated:...
     
  3. macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #3
    If you have multiple object you would have to use arrayWithObjects just an FYI.
     
  4. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    OP (and ArtOfWar), if you look at the UITabBarController header you'll find the relevant property:

    Code:
    @property(nonatomic,copy) NSArray *viewControllers;
    That's the method you're using so the required parameter is an array of view controllers.
     

Share This Page