0

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;
  • You have four lines of code, which one creates the error? Also take some time to read how to format questions, in particulat to format code, hint" mouse over the {} symbols in the edit header. – zaph May 15 '15 at 13:34
  • Which version of Xcode are you using? – chedabob May 15 '15 at 13:36
  • That was in the original question but deleted in an edit: Xcode4. – zaph May 15 '15 at 13:38
  • i hav posted the link for code i tried!!! above and i am using xcode 4.2 –  May 15 '15 at 13:38
  • @gopinath We are not interested in seeing the tutorial code. I for one beliece the tutorial is correct and this infer that the problem is in your implementation. So it is your code that is important to see. But the error may be your implementation of the Storyboard. – zaph May 15 '15 at 13:40
  • It really would be much better to use a current version of Xcode which is now 6.3.1. Xcode 4.2 may well be incompatible with the tutorial you are using. – zaph May 15 '15 at 13:43

3 Answers3

1

Using the subscript syntax (i.e. 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).

omz
  • 53,243
  • 5
  • 129
  • 141
0

If you're just trying to get the first object of the array, why not use firstObject?

UINavigationController *navigationController = [[tabBarController viewControllers] firstObject];
sharpnado
  • 21
  • 4
  • 1
    Good style but what would that work when [0] failed? – zaph May 15 '15 at 13:18
  • Maybe? It depends on what OP is actually doing. I'm having difficulty understanding what OP is asking for. – sharpnado May 15 '15 at 13:21
  • @zaph `firstObject` was introduced in iOS 4, `objectAtIndexedSubscript:` (which `[0]` basically uses under the hood) in iOS 6, so on iOS 5, the first would work, but the latter wouldn't. – omz May 15 '15 at 13:49
  • I didn't spot that OP was using Xcode 4.2, so you're correct. – sharpnado May 15 '15 at 13:51
  • This is actually a correct solution but lacking the reason given by @omz. Anna removed the xcode4 tag in an early edit so that information is missing. – zaph May 15 '15 at 13:57
-1

You can use below code

UINavigationController *navigationController = 
    [tabBarController.viewControllers objectAtIndex:0];

Refer the below links..regarding error and explanation..!

What is a non-fragile ABI?

Subscript requires size of interface 'NSArray', which is not constant in non-stable ABI

Hope it helps you...!

Community
  • 1
  • 1
Vidhyanand
  • 5,369
  • 4
  • 26
  • 59
  • Why do you think using `objectAtIndex:` is a solution to the error? – zaph May 15 '15 at 13:46
  • He asked where to insert object at index code..So I have answered the solution relative to his question..! He is not asked about the error anywhere..Hope you understand it...! – Vidhyanand May 15 '15 at 13:55
  • This is actually a correct solution but lacking the reason given by @omz. – zaph May 15 '15 at 13:56
  • thank u for your answer it rectifies error but can you please tell me what is this error about!! please –  May 16 '15 at 04:32
  • @ zaph hi could u please explain me about this error more specific to understand since i am new to this storyboard –  May 16 '15 at 05:13
  • Refer the above links which I attached to my answer..It will give u idea about the error...! – Vidhyanand May 18 '15 at 04:52
  • okay got it!!!! is there any possibility to change the back ground color of a custom type prototype cell in tableview.. dont know how to change the backgroun color of custom created prototypecell!!! i tried to change using user defined run time attributes in custom class but i cant find the key color in it!!!! –  May 18 '15 at 09:47