I am trying a tutorial for using story board from ray. I am using a tab bar controller connecting a tableview embedded with navigation controller, and this table view is named as players and a view controller connecting tab bar controller named as gestures. Displaying players game, name and rating in players tableview by storing those details in an object. So i have created a new file player with base object to store them as properties now i have to store those properties in an array of the view controller called player view controller and then i have to make the array and some test Player objects in the App Delegate and then assign it to the PlayersViewController's players property using an instance variable.so In AppDelegate.m, i imported player and player view controller.h headers and add a new instance variable named _players. so my code in app delegate.m is as below the error is subscript requires size of interface 'NSARRAY' which is not constant in non-fragile ABI at the line viewcontrollers[0].
#import "AppDelegate.h"
#import "Player view controller.h"
#import "player.h"
@implementation AppDelegate {
NSMutableArray *_players; }
@synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_players=[NSMutableArray arrayWithCapacity:20];
player *player1=[[player alloc]init];
player1.name=@"name";
player1.game=@"cricket";
player1.rating=3;
[_players addObject:player1];
player1=[[player alloc]init];
player1.name=@"name";
player1.game=@"football";
player1.rating=3.5;
[_players addObject:player1];
player1=[[player alloc]init];
player1.name=@"tony";
player1.game=@"handball";
player1.rating=4;
[_players addObject:player1];
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController = [tabBarController viewControllers][0];
UINavigationController *navigationController = [tabBarController viewControllers][0]; /*at this point i get a error as [error: subscript requires size of interface 'NS ARRAY' which is not constant in non-fragile ABI] */
Player view controller *playersViewController = [navigationController viewControllers][0];
playersViewController.players = _players;
return YES;
Using the subscript syntax (ie someArray[0]
) requires Objective-C features that were introduced in the iOS 6 SDK, but afaik Xcode 4.2 only supports iOS 5, so you'd either have to use the old syntax:
UINavigationController *navigationController = [[tabBarController viewControllers] objectAtIndex:0];
//alternatively:
UINavigationController *navigationController = [[tabBarController viewControllers] firstObject];
...or update to a more recent version of Xcode (you can't even submit to the App Store with Xcode 4.2, as far as I'm aware).
如果您只是想获取数组的第一个对象,为什么不使用firstObject?
UINavigationController *navigationController = [[tabBarController viewControllers] firstObject];
You can use below code
UINavigationController *navigationController =
[tabBarController.viewControllers objectAtIndex:0];
Refer the below links..regarding error and explanation..!
Subscript requires size of interface 'NSArray', which is not constant in non-stable ABI
Hope it helps you...!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.