iOS switch view in a navigation controller from the app delegate - ios

I'm trying to switch to another view in my navigation controller when the application didRecieveRemoteNotification is triggered.
Here is my current code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
ConvViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:#"chatConversation"];
[(UINavigationController*)self.window.rootViewController pushViewController:ivc animated:NO];
For some reason i get (lldb) error on the second line.
Any ideas what I'm doing wrong?
Edit
I'm using storyboard segue identifier: chatConv
to my Custom Class: ConvViewController and my custom class has a Storyboard ID: chatConversation
Here is my Storyboard:

chatConversation should be a ViewController in MainStoryboard.storyboard. In MainStoryboard.storyboard, select your chatConversation ViewController. In the Identities panel, make sure your custom class is set to ChatViewController.

instantiateViewControllerWithIdentifier takes a view controller identifier not a segue identifier. So something like:
[storyboard instantiateViewControllerWithIdentifier:#"convViewController"];

Related

UIStoryboard open from another UIStoryboard

I have a problem with calling one UIStoryboard from the second. My first Storyboard - Main, second - Management. When you click UIButton no action occurs. My source code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Management" bundle:[NSBundle mainBundle]];
UIViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:#"Management"];
[self.navigationController pushViewController:yourViewController animated:YES];
There are so many reasons may be here.
1. You might forgot to setup IBAction outlet to your UIButton
2. Storyboard names may not match you specify in your code
3. [storyboard instantiateViewControllerWithIdentifier:#"Management"]; are you sure you specified the same Storyboard ID for this controller?
4. In order to check all these suggestions it's enough just to set breakpoint on first line of your code and try to reproduce the situation.
Many wrong things can happen in that code.
First of all be sure that your action is well connected, put a breakpoint in your action to see if that is being called.
Second be sure that the storyboard name is correct, put a breakpoint after storyboard and check if it isn't nil (po storyboard in the debug console).
Second be sure that the "Management.storyboard" has a ViewController with the identifier "Management". So put a breakpoint after yourViewController to check if it is nil (po yourViewController in the debugger console).
Finally be sure that the view controller where you have the action is inside the navigation controller. So check if self.navigationController is nil (po self.navigationController in the debugger console after you stopped in the action's code)
Need replace old code by this.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Management" bundle:[NSBundle mainBundle]];
UIViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:#"ManagementIDS"];
[self presentViewController:yourViewController animated:YES completion:nil];
If you prefer doing it in interface builder than in code:
You can now create a storyboard reference in interface builder. That means you can link a storyboard from another storyboard. Target must be ios9.
https://developer.apple.com/library/prerelease/watchos/recipes/xcode_help-IB_storyboard/Chapters/AddSBReference.html#//apple_ref/doc/uid/TP40014225-CH49-SW1
check 19:00
https://developer.apple.com/videos/wwdc/2015/?id=407

Get instance of view controller in AppDelegate.m

In my app I've three view controller embedded in a UITabBarController. The second view controller embed a table view controller. Now I've this bug: I go to the second view controller, then I press home button and the app goes in background. When the app is closed I receive a push notification, so when I open the app it shows me the second view controller with table view without any changes. How I can update the table view automatically? For now I'm using the UIRefreshControl, but I will do it automatically, how I can do that?
You can get your VC's instance from storyboard. First you have to set storyboard ID to your VC
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
YourViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:#"YourViewControllerID"]; // here YourViewControllerID is storyboard Id of your VC.

Unable to pushViewController iOS

I am using storyboard in my app, :
I have Button in my View, On click of button i want to navigate to new View
But when i click on button nothing happens,
Here is my Code:
- (IBAction)JoinClicked:(id)sender{
JoinWithViewController *detail_view_controller = [[JoinWithViewController alloc] initWithNibName:#"JoinWithViewController" bundle:nil];
[self.navigationController pushViewController:detail_view_controller animated:YES];
}
Where i am doing mistake , please help.
Thanks in advance.
Set storyboard id of view controller in story board in identity inspector
Make a reference to your storyboard like
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
then to your controller
YourController *vc = [storyboard instantiateViewControllerWithIdentifier:#"YourController"];// storyboardId
[self.navigationController pushViewController:vc animated:YES];
and you can also make segue and do
[self performSegueWithIdentifier:#"YourSegueIdentifier" sender:sender/nil];
use this one :
- (IBAction)JoinClicked:(id)sender{
[self performSegueWithIdentifier: #"JoinWithIdentifier" sender: self];
}
and add segue in storyborad like
Make an identifier for your push-segue in storyboard.
then use
[self performSegueWithIdentifier:#"YourSegueIdentifier" sender:nil];
When using story boards you should use segues for as much navigation as possible.
Your code seems fine, please verify your outlets correctly configured or not in xib or storyboard.
Edit:
You are using storyboard and wants the xib file to get pushed onto your view controller if I am not wrong, you can drag another view controller in storyboard and name it JoinWithViewController and push using segue on button click. That is much easier than what your trying to do here.

Identifying a UIStoryboard

How do you identify a UIStoryboard?
The class has methods which create and instantiate but I don't see an #property with something like name. E.g.
Getting a Storyboard Object
+ storyboardWithName:bundle:
Instantiating Storyboard View Controllers
– instantiateInitialViewController
– instantiateViewControllerWithIdentifier:
Any suggestions?
====
UPDATE
I was hoping for something like self.storyboard.name or [self.storyboard description], e.g.:
NSLog(#"This Storyboard is: %#", self.storyboard.name);
Perhaps it's not meant to be.
You can identify a storyboard by its name in the project navigator:
You can identify a view controller from a storyboard by setting its Storyboard ID in the identity inspector in interface builder:
Once you have these, then you can access them through your code:
UIStoryboard *iPhoneStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
ViewController *firstViewController = [iPhoneStoryboard instantiateViewControllerWithIdentifier:#"FirstViewController"];

Load an storyboard (UITableViewController) from ViewController

I want to load an storyboard from a ViewController. Currently my code looks as follows:
- (IBAction)Button_Action:(id)sender
{
UIStoryboard * sb = [UIStoryboard storyboardWithName:#"AddReportView" bundle:nil];
AddReportViewVC * vc = [sb instantiateViewControllerWithIdentifier:#"AddReportView"];
[self.navigationController pushViewController:vc animated:true];
}
The view is pushed but I do not see my expected View Controller (which is a UITableViewController) instead I just see an empty gray view controller.
Remember that in both the identifier name and the storyboard name, capitalization matters. I've gotten this wrong so many times...
The problem was that a function of the generated code by xcode coused the table view controller to flush the content.

Resources