Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JacekK

macrumors newbie
Original poster
Jan 21, 2013
1
0
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 "@"
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,555
6,053
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:...
 

KoolStar

macrumors demi-god
Oct 16, 2006
825
9
Kentucky
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:...

If you have multiple object you would have to use arrayWithObjects just an FYI.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.