Shows blank view when loading view controller from StoryBoard - ios

I have a project which is already in App Store.
Now I need to add some more screens using storyboards to the project. The project was previously implemented using nib files.
I have created storyboard for the new view controller which I have added. When the view controller is called it comes up almost blank, none of the views which I have added for the controller are not showing up.
I have added below code how i'm loading the view controller from story board.
-(void)gotoEventsScreen
{
EventsListViewController* eventsScreen = [[UIStoryboard storyboardWithName:#"EventsScreen" bundle:nil] instantiateInitialViewController];
[self.navigationController pushViewController: eventsScreen animated:YES];
}
Note: I have made EventsListViewController as initialviewcontroller and it also has identifier.
I have also tried to load with identifier still it shows me the blank screen.

Actually there was some problem with my project base class view controller which consists the initWithCoder method which was not calling its super class method.

Related

iOS - Pushing to a View Controller that is not in the Storyboard

Ok, first let's name things:
I have a table view in my root view controller wich we'll call "HomeViewController". In that table view each cell tap will push a different view controller. This collection of view controllers we'll call "DetailViewControllers".
I am perfecly aware that I can make this work by simply loading and pushing each of the DetailViewControllers programmatically inside the didSelectRowAtIndexPath method. I want to do something different instead using storyboard and a prototype cell and I'm not succeeding, so I'm looking for some advice since I'm not too well versed in storyboards and segues.
The behavior I'm trying to achieve here is:
I'll have a segue from a prototype cell in the table view in my HomeViewController. That segue pushes a "base" view controller, from which every DetailViewController inherits. These view controllers don't have an assigned view controller in the storyboard either.
In the prepareForSegue method I want to cast the 'destinationViewController' to the 'right' class. The app crashes at that point saying it "Could not cast value of type 'BaseTestViewController' to 'TestViewController'.". Which is totally understandable.
So, my question is: is there a way to make a segue work like that?
You can't create segues programatically. Segues don't exist without a storyboard. You can just push to a view controller via loading a nib file.
Here's how you do it.
Let's say you have a nib file containing the layout of the view for the main view of your view controller. We'll name it "Test" for instance.
Go to that nib file, click file's owner.
Change class to the name of your view controller. In my case, I named it ViewController.
Right click on file's owner. Link the outlet of view of your view controller to the view in the nib file.
Then in the view controller where you want to transition to that view controller, you do it like this:
UIViewController *controller = [[UIViewController alloc] initWithNibName:#"Test" bundle:[NSBundle mainBundle]];
[self presentViewController:controller animated:YES completion:nil];
It will present the view controller modally.
If you are embedding a navigation controller then you can do it like this:
[self.navigationController pushViewController:controller animated:YES];
Hope it helps.
Try like this without storyboard segue.
let objDestVC = self.storyboard.instantiateViewControllerWithIdentifier("DestVCStroyboardId") as! DestinationViewController
self.navigationController?.pushViewController(objDestVC, animated: true)

Working with View Controllers in Storyboards

I'm begin learn iOS and i have a question: when i launch the project, app will load all view controller or just the Initial View Controller in Main.storyboard?
In case, my app have a lots of view controller, e.g 50 VC, i want to check 50 VC be loaded in one time or each VC be loaded when i call e.g like this :
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"myViewController"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
After research and ask some friends, i see in Apple doc:
The main storyboard is defined in the app’s Information property list
file. If a main storyboard is declared in this file, then when your
app launches, iOS performs the following steps:
It instantiates a window for you.
It loads the main storyboard and instantiates its initial view controller.
It assigns the new view controller to the window’s rootViewController property and then makes the window visible on the
screen.
It just load only Initial View Controller set in Main.storyboard. You can set any view controller as initial view controller from storyboard-> select any view controller -> go to utility portion of xCode-> go to attribute inspector-> now check is Initial View Controller.
From Docs :
A UIStoryboard object encapsulates the view controller graph stored in
an Interface Builder storyboard resource file. This view controller
graph represents the view controllers for all or part of your
application’s user interface. Normally, view controllers in a
storyboard are instantiated and created automatically in response to
actions defined within the storyboard itself. However, you can use a
storyboard object to instantiate the initial view controller in a
storyboard file or instantiate other view controllers that you want to
present programmatically.
StoryBoard will load just initial viewController on load of the app. Other view controllers will load on performing segues or manually by following methods.
- instantiateInitialViewController
- instantiateViewControllerWithIdentifier:
Read more at here

How to Navigate view Controller form Navigation Controller Programmatically

Hi I'm trying navigate to view controller form the navigation view controller with connect using the objects
i want to do by programmatically but its not working its showing the black screen. Please tell me how to resolve this.
- (IBAction)reg:(id)sender {
pollpoliticalViewController *vc2 = [[pollpoliticalViewController alloc] init];
[self.navigationController pushViewController:vc2 animated:YES];
}
The above code i have used to navigate but its giving black color screen its not showing the view controller please tell me where I'm doing wrong.
Thanks.
Nothing is wrong with the above code.
As I understand what you are doing, you have a view controller class called pollpoliticalViewController. My first suggestion would be for you to look into the accepted coding style in Objective-C. You should always capitalise classes. In this instance the class should have been called 'PollPoliticalViewController`. Obviously this is not the source of the problem though.
The problem will be with the view controller itself. In the code for pollpoliticalViewController you are doing something wrong which is not displaying the view.
The view controller may actually be styled inside of a .xib file, in which case you should be initialising the view controller like this:
pollpoliticalViewController *pollVC = [[pollpoliticalViewController alloc] initWithNibName:#"pollpoliticalViewController" bundle:nil];
If the view controller is defined inside of a storyboard, you will have to give the view controller a 'Storyboard ID', for example; 'PollPoliticalVCID'. You then need to initialise it like this (assuming your storyboard is called "MainStoryboard":
pollpoliticalViewController *pollVC = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:#"PollPoliticalVCID"];
EDIT
The storyboard name is found when you open the storyboard, do not select any view controller. Open the Utilities side bar (on the right side of Xcode), select the first item, and you can find the name under Identity and Type. I have included an image.

My app requires using instantiateViewControllerWithIdentifier - why?

I have added a Storyboard file to an app that initially had none. For some reason, I could not get my custom UIViewController to display correctly until I added this into didFinishLaunchingWithOptions:
ActivityViewController *viewController = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:NULL] instantiateViewControllerWithIdentifier:#"ActivityViewController"];
Why do I need to force the use of my storyboard like this? The iOS template projects (Single View, Master-Detail etc) doesn't need this.
Checklist:
Xcode Project Summary→Main Storyboard is set correctly to "MainStoryboard".
Interface Builder→Identity Inspector→Class is correctly set to "ActivityViewController".
Interface Builder→Identity Inspector→Storyboard ID is also set to "ActivityViewController", but this is only because it's needed by instantiateViewControllerWithIdentifier.
You do not need to call instantiateViewControllerWithIdentifier if you set Is Initial View Controller on your "ActivetyViewController" in the storyboard. The initial view controller will have an arrow pointing at it.

Show custom view after person is selected in peoplePickerNavigationController

I'm running into trouble with what I think is a pretty basic task. Within peoplePickerNavigationController:peoplePicker:shouldContinueAfterSelectingPerson: i want to show my own view rather than the standard person view. I'm using a Storyboard, but don't think I can simply manually segue to a window here so I'm thinking I need to create a new XIB with a View Controller in it. I'm setting the Class of the View Controller to my custom View Controller in IB. Then in peoplePickerNavigationController:peoplePicker:shouldContinueAfterSelectingPerson: I'm doing:
MyVC *myVC = [[MyVc alloc] initWithNibName:#"XIBFileName" bundle:nil];
[self presentModalViewController:myVC animated:YES];
In my View Controller initWithNibName gets called, but not viewDidLoad. What am I doing wrong here?
Just try [peoplePickerVC presentModalViewController:myVC] instead of presenting from self.
The issue is that the peoplepickerviewcontroller will be in the top of the navigation stack. Becuase you wud've presented the peoplepicker from self. As this is the case, you wont be able to present/push from self as its not at the top of the navigation stack.
Otherwise once the peoplepicker has been poped, then you can further present from self.

Resources