SWRevealViewController push Segue - xcode

I am trying to use a SWrevealViewController for sidemenu . One of the options on it is "User Profile" . Since I access user's profile from various other views , I would like to have to have a push segue to this VC. However , a push segue is not working from SWRevealViewController to UserProfileVC.
Can anyone suggest how I may use a push sugue from SWRevealVC?

Here's my solution:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil]
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"YOUR_VC_STORYBOARD_ID"];
SWRevealViewControllerSeguePushController *segue = [[SWRevealViewControllerSeguePushController alloc] initWithIdentifier:#"ANY_ID" source:self destination:vc];
[segue perform];

Swift version will be
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("LoginRoot") as! UINavigationController
let segue = SWRevealViewControllerSeguePushController.init(identifier: SWSegueRearIdentifier, source: self, destination: vc)
segue.perform()
Navigation controller is UIViewcontroller. i used navigation controller otherwise use UIViewController object.

Create a custom segue from your Reveal View Controller to your side menu view controller using the storyboard editor. Set the identifier as "sw_rear", kind as "Custom" and class as "SWRevealViewControllerSegueSetController".
With this, if you create ordinary "push" segues from your menu view controller to other view controllers they should be pushed normally.

Related

Could not set the title of tableview

I embedded tableviewcontroller into a navigation controller, set the title, but it does not show when I run the app.
What is wrong?
This is the setting of the tableviewcontroller
Here is the setting of the navigation controller
First check, your NavVC must be initial VC.
If not then try this piece of code
-(void) viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:NO animated:YES];
}
you must be presenting the plain table view instead of navigation controller. What you need to do is make you tableview as root view for a navigation controller and present the navigation controller.
var nav: UINavigationController = UINavigationController(rootViewController: vc)
//then present the nav
Change the initial VC from Navigation Controller to your TableViewController
I did not set the StoryboardId for Navigation controller.

What object a menuitem action triggered segue should be called on?

I have a menuitem selection triggered segue you can see on the attached pictures
The NSMeniItem connections:
The segue it triggers:
How can I trigger the segue programmatically.
It has an identifier, it's ok.
But what object on I have to call the
(void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender;
#vadian pointed me out that I need the windowcontroller the segue should be called on first and I can get it like this
let mainStoryBoard = NSStoryboard(name: "Main", bundle: nil)
windowController = mainStoryBoard.instantiateController(withIdentifier: "Preferences") as! NSWindowController
windowController.showWindow(self)
where
windowController is a property in AppDelegate
"Preferences" is the identifier in the Storyboard
it has benefit of getting a reference to the window controller itself
as I did not need the reference currently just wanted to trigger the segue i stayed with the following solution
[NSApp sendAction:mPreferencesMenuItem.action to:mPreferencesMenuItem.target from:mPreferencesMenuItem];
where mPreferencesMenuItem is the menuitem that triggers the segue
NSViewController and NSWindowController conforms to the NSSeguePerforming protocol. So in your controller subclass you can call [self performSegueWithIdentifier:(NSString *)identifier sender:(id)sender];

Xamarin IOS how to create a Stroy Board from exisitng files?

I found this navigation bar that i want to use but a Cant seem to find the story board for it? or am i looking in the wrong place, How would i generate a story board for it?
here is the link to the bar: https://components.xamarin.com/view/flyoutnavigation
You don't generate a storyboard for it. You put a generic view into your storyboard and set it's class to be a custom subclass of FlyoutNavigationController, and set it as the root view. You can then grab all of the ViewControllers that are controlled by the FlyoutNavigationController by using something similar to the following Objective-C code:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"myViewController"];
or, in C#
UIStoryboard sb = UIStoryboard.FromName("MainStoryboard", null);
UIViewController vc = sb.InstantiateViewController("myViewController");
Here's the link for storyboarding
http://developer.xamarin.com/guides/ios/user_interface/introduction_to_storyboards/

What is a StoryBoard ID and how can I use this?

I am new to IOS developing and recently started in Xcode 4.5. I saw for every viewController that i could set some identity variables including the storyboard ID. What is this, and how can I use it?
I started searching on stackoverflow and couldn't find any explanation for it.
I assumed it's not just some stupid label that I can set to remember my controller right? What does it do?
The storyboard ID is a String field that you can use to create a new ViewController based on that storyboard ViewController. An example use would be from any ViewController:
//Maybe make a button that when clicked calls this method
- (IBAction)buttonPressed:(id)sender
{
MyCustomViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"MyViewController"];
[self presentViewController:vc animated:YES completion:nil];
}
This will create a MyCustomViewController based on the storyboard ViewController you named "MyViewController" and present it above your current View Controller
And if you are in your app delegate you could use
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard"
bundle: nil];
Edit: Swift
#IBAction func buttonPressed(sender: AnyObject) {
let vc = storyboard?.instantiateViewControllerWithIdentifier("MyViewController") as MyCustomViewController
presentViewController(vc, animated: true, completion: nil)
}
Edit for Swift >= 3:
#IBAction func buttonPressed(sender: Any) {
let vc = storyboard?.instantiateViewController(withIdentifier: "MyViewController") as! ViewController
present(vc, animated: true, completion: nil)
}
and
let storyboard = UIStoryboard(name: "MainStoryboard", bundle: nil)
To add to Eric's answer and update it for Xcode 8 and Swift 3:
A storyboard ID does exactly what the name implies: it identifies. Just that it identifies a view controller in a storyboard file. It is how the storyboard knows which view controller is which.
Now, don't be confused by the name. A storyboard ID doesn't identify a 'storyboard'. A storyboard, according to Apple's documentation, 'represents the view controllers for all or part of your app’s user interface.' So, when you have something like the picture below, you have a storyboard called Main.storyboard which has two view controllers, each of which could be given a storyboard ID (their ID in the storyboard).
You can use a view controller's storyboard ID to instantiate and return that view controller. You can then go ahead to manipulate and present it however you want. To use Eric's example, say you want to present a view controller with identifier 'MyViewController' when a button is pressed, you would do it this way:
#IBAction func buttonPressed(sender: Any) {
// Here is where we create an instance of our view controller. instantiateViewController(withIdentifier:) will create an instance of the view controller every time it is called. That means you could create another instance when another button is pressed, for example.
let vc = storyboard?.instantiateViewController(withIdentifier: "MyViewController") as! ViewController
present(vc, animated: true, completion: nil)
}
Please take note of changes in syntax.

How to use custom Navigationcontroller in AppDelegate by using a Storyboard

I've got a problem concerning Navigationcontroller in AppDelegate. I'm using a storyboard, which looks like this:
As a result of using Push notifications, i've got the following function in my AppDelegate File:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
//...
}
When the notification arrives I want to initialize the "Detail View" - Controller which needs an ID as a parameter. This ID is part of my payload so it is present in didReceiveRemoteNotification.
I'd like to to the follwing:
DetailView *detail = [storyboard instantiateViewControllerWithIdentifier:#"detail"];
detail.conversationID = theID;
[self.navigationController pushViewController:detail animated:YES];
My question at this point is: how can I get the navigation controller? I've searched for a function like "getNavigationControllerByIdentifier" or something like this, but found nothing. I can't instantiate the Detail View Controller directly because the navigationbar is missing there.
I hope you understand what I mean - if you think my approach is completly wrong please correct me ;o)
Just another small information: It's not important for me that the back button in the Detail View Controller goes back to the Table View - it's enough when it links to the controller with the button "Load Table View".
Thank you for help!
UINavigationController is a UIViewController subclass and can also be assigned an identifier in the storyboard.
Use -instantiateViewControllerWithIdentifier: to create the UINavigationController and it's root view controller. You may need to instantiate all of the intermediate controllers in code and modify the navigation controller's viewControllers property to set up the appropriate navigation stack. This way when the app launches into the detail view, they can find their way back as if they had manually pushed all the way through via the interface.
You can use rootViewController on your window object.
UIViewController *rootViewController = self.window.rootViewController;
// You now have in rootViewController the view with your "Hello world" label and go button.
// Get the navigation controller of this view controller with:
UINavigationController *navigationController = rootViewController.navigationController;
// You can now use it to push your next view controller:
DetailViewController *detail = [navigationController.storyboard instantiateViewControllerWithIdentifier:#"detail"];
detail.conversationID = theID;
[navigationController pushViewController:detailViewController animated:YES];

Resources