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 (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).
If you're just trying to get the first object of the array, why not use 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..!
What is a non-fragile ABI?
Subscript requires size of interface 'NSArray', which is not constant in non-stable ABI
Hope it helps you...!
Related
I have had a published universal app for many years that has worked fine. Now since the iOS13 update it simply starts to a solid white screen. The only exception is if I run it on an iPad and change orientation of the device. Than the app finally appears as it always has. I have placed a breakpoint in my delegate file in the Application method and another in my rootviewcontroller in the viewDidLoad method. In iOS 12 both breakpoints get hit and everything runs as it always has. In iOS 13 the rootviewcontroller breakpoint never gets reached. The app is very old and uses plain old XIB files with no Storyboards.
The code in my delegate is this;
#import "AppDelegate.h"
#import "RootViewController.h"
#implementation AppDelegate
#synthesize window, splitViewController;
#synthesize managedObjectContext = _managedObjectContext;
#synthesize managedObjectModel = _managedObjectModel;
#synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window setRootViewController:self.splitViewController];
[self.window makeKeyAndVisible];
return YES;
}
Issue with iOS 13 Split view controller. If you have navigation controller embedded to Master/Detail view controller it just loads the navigation controller.
To fix that issue create a custom class from UISplitViewController and assign that to your splitviewcontroller in storyboard and programatically add Navigation controller and masterViewcontroller to that UISplitViewController. That should load your view properly. This code goes in the viewdidload or willappear of the UISplitviewcontroller class.
Sample code.
MasterViewController *master = [[MasterViewController alloc] init];
UINavigationController *tableViewNavigationController = [[UINavigationController alloc] initWithRootViewController:master];
UINavigationController *navC = [[UINavigationController alloc] init];
self.viewControllers = [NSArray arrayWithObjects:tableViewNavigationController,navC, nil];
This fixed my issue had similar problem with iOS. Hope that helps.
I am trying to access an Array variable in a view controller in an application that is using storyboards.
BACKGROUND:
I have been following along with the Ray Wenderlich tutorial on Storyboards.
Once I finished the tutorial, I went back tried a different route, though I’m having trouble accessing a view controller. Everything is pretty much the same except my set up is the initial Scene is a View Controller. I am to the part where the author is adding some data to NSMutableArray in his table.
THEIR CODE THAT I AM USING AS A GUIDE
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController = [tabBarController viewControllers][0];
PlayersViewController *playersViewController = [navigationController viewControllers][0];
playersViewController.players = _players;
I was hoping it would be a simple as replicating what I had seen with view controllers, passing along the appropriate type, but no.
I have View Controller > View Controller > Navigation View Controller > UITableViewController.
MY CODE:
UIViewController *vc = (UIViewController*)self.window.rootViewController;
UIViewController vc1 = [vc viewController][0];
UINavigationController *nc = [vc1 viewController][0];
SearchViewTableViewController *svc = [nc viewControllers][0];
svc.myarray = _myarray;
I have tried multiple combinations and am getting nowhere.
There has got to be a simpler way for me to reference classes/view/scenes.
Any help?
Make sure you are importing the ViewController header file.
Make sure you have given you ViewController a Storyboard identifier.
Then something like this should work:
MyViewController *myVC = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"MyViewController"];
myVC.myMutableArray = [NSMutableArray new];
....
I'm trying to reference a UITabController from my app delegate, even though it isn't my rootViewController. How do I do it?
UITabBarController *tabBarController =
(UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController =
[[tabBarController viewControllers] objectAtIndex:1];
DocumentsViewController *ViewController =
[[navigationController viewControllers] objectAtIndex:0];
I want to change the first line of code so it doesn't reference the "rootViewController" but directly references my UITabBarController, because I have a start screen that I want to use for the app.
Declare your UITabBarController in the .h of your AppDelegate.
Get a reference to your AppDelegate:
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
Then you can do:
delegate.tabBarController;
Or you could do:
[(AppDelegate*)[UIApplication sharedApplication] delegate] tabBarController];
Also, make sure to include "AppDelegate.h" in your rootViewController/
EDIT:
Add this to the .h of your rootViewController class so that it is publicly accessible:
#property SecondViewController *mySecondViewController;
Now, when you instantiate your SecondViewController before you present it modally make sure to do it like this:
self.secondViewController = [[SecondViewController ...
You should now be able to reference your secondViewController from your AppDelegate like this:
self.rootViewController.mySecondViewController
I am relatively new to iOS, hence I apologize for any inconsistency in my question. I need help with the following issue with an app I'm trying to build. My issue is this: The app i am working has a navigation based functionality with a tableview(daily filled by user) and a detailed tableview listing the inputs of the user, but this is just one functionality of the app.
I want to have a main tab based view where one of the tabs(each tab representing a functionality) points to this module.
I wanted to ask for steps and changes i need to make to for example app delegate or rootviewcontroller(I can post the code if it helps better) to make is so that the app starts with a mutli-tabbed bar view where one tab refers to view linked to the rootviewontroller of the navigation-based app.
For summary: Need a main tab bar view where one tab points to the rootviewcontroller highlighted in the screenshot(link below)
If helpful here is a relevant function code i have in app delegate :
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
RootViewController *rootViewController = (RootViewController *)[[navigationController viewControllers] objectAtIndex:0];
rootViewController.managedObjectContext = self.managedObjectContext;
//Next TWO LINES FOR COLOR BACKGROUND
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundColor:[UIColor redColor]];
}
PS:Here is the screenshot for the storyboard: where i would like to have one tab refer to the view(highlighted in the screenshot) which is linked class rootviewcontroller.m/h
The screenshot: http://i.stack.imgur.com/G9AXI.png
edit: The actual question can be seen as: How and what do i need to do to have a tabbarviewcontroller which i would add with storyboard become my rootviewcontroller instead of the navigationcontroller(highlighted in black in the screenshot: http://i.stack.imgur.com/G9AXI.png).
My current rootviewcontroller.m manages anything related to the tableview of the current navigationviewcontroller, do i need to change that also?.
I apologize for excessiv details, I am really new to iOS dev.
From this one http://i.stack.imgur.com/suLBm.png I tried to embedd in tab barviewcontrol only with storyboard to this one http://i.stack.imgur.com/TZxLo.png I tried to embedd in a tab controller just by story but i get an error :'NSInvalidArgumentException', reason: '-[UIViewController setManagedObjectContext:]: unrecognized selector sent to instance 0x8184e30'
classes related to this are(especially rootviewcontroller.m which is a navigationcontroller for now:
AppDelegate.{h,m}
Configures the Core Data stack and the first view controllers.
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
RootViewController *rootViewController = (RootViewController *)[[navigationController viewControllers] objectAtIndex:0];
rootViewController.managedObjectContext = self.managedObjectContext;
}
RootViewController.{h,m}
Manages a table view for listing all values entered. Provides controls for adding and removing these values.
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = self.editButtonItem;
}
DetailViewController.{h,m}
Manages a detail display for display details of each entered value.
My initial guess is that i need to change the rootviewcontroller appdidfinishlaunching.
Any suggestions ?
In fact now you have:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
RootViewController *rootViewController = (RootViewController *)[[[[tabController viewControllers] objectAtIndex:0] viewControllers] objectAtIndex:0];
rootViewController.managedObjectContext = self.managedObjectContext;
}
So you actually need a UITabBarViewController in the Storyboard and you can point to the UINavigationController if you want the ability to push other controllers.
You don't need other UINavigationControllers as I saw in your screenshot, as long as the rootviewcontroller is an UINavigationController.
You can add the UINavigationController as first of the tabs and then you can go and fill the other tabs with the viewcontrollers that you need displayed.
SO basically you need to create UITabBarController as rootviewcontroller.
Let me know if I understood your question correctly.
Here is an example of UITabBarController :
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
//Here you set your controller
UIViewController* centerController = [[UIViewController alloc]init];
UINavigationController *navCenter = [[[UINavigationController alloc] initWithRootViewController:centerController] autorelease];
UITabBarController *tabBarController = [[[UITabBarController alloc] init] autorelease];
tabBarController.viewControllers = [NSArray arrayWithObjects:navCenter,nil];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.rootViewController = tabBarController;
return YES;
}
Let me know if it worked.
You should have something like this :
I'm trying to use CoreData with Storyboard on a TabBar - NavigationController - TableViewController configuration.
When trying to assign the Managed Object Context to the TableViewController I get
[UITabBarController topViewController]: unrecognized selector sent to instance
If I understand correctly, the problem is that I'm not getting the TableViewController instance. I've tried many things but I don't seem to be getting anywhere.
Your help is much appreciated.
I was able to fixit using Matthijs Hollemans tutorial on raywenderlich.com.
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController = [[tabBarController viewControllers] objectAtIndex:0];
MyViewController *controller = [[navigationController viewControllers] objectAtIndex:0];
controller.managedObjectContext = self.managedObjectContext;