side menu with UITabBarController and storyboards ios - xcode

I would like to implement a side menu bar in my application, I have UITabBarController and Storyboard, I have tried to integrate the menu bar MFSideMenu , but there is not a menu with UITabBarController for storyboard, just for nib files, so I need your help.
Many thanks

You simply do the following:
Create a UIStoryboard instance of the the relevant storyboard you need to set as the center controller, in case you have multiple storyboards. Use HomeStoryboard if you have just the standard storyboard in use.
Instantiate the view controller that is the initial view controller of your app, based on it's storyboard ID. You will have to set this in Storyboard (utilities pane).
Instantiate the view controller you want to use as the left menu.
Create an instance of MFSideMenuContainerViewController, with the center and left(or right, or both) menu controller you just created.
Set the instance of your MFSideMenuContainerViewController as the rootViewController of your app window.
Sample code:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"HomeStoryboard" bundle:nil];
UIViewController *homeViewController = [sb instantiateViewControllerWithIdentifier:#"homeViewController"];
UIViewController* leftMenuViewController = ......//Instantiate your left menu controller
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:homeViewController
leftMenuViewController:leftMenuViewController
rightMenuViewController:nil];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];

Related

How to embed a storyboard view controller in an NSScrollView OS X (10.10) to make a complex inspector view?

I'm looking at WWDC 2014 video, "212: Storyboards and controllers on OS X". In this video they claim that Pages UI does/could be arranged using Storyboards on OS X (see below).
However, in Pages UI the inspector view is very long and is embedded in a scroll view (you can verify this my two-finger scrolling in Page.app inspector view), also some inspector items are themselves contained in (some type of custom) disclosure view. It doesn't seem to be possible to embed a storyboard view controller in scroll view because there is no corresponding to "scroll view controller" class. Is that right?
How can a storyboard view controller's view be embedded in a scroll view on a storyboard?
I have tried direct embedding at run time, however, this is very hackish and does't work reliably (problems with auto-layout). This route still might be possible, but I wanted to get advice before going too far. For real UI it might be the case of falling back to XIBs.
- (void)viewDidLoad {
[super viewDidLoad];
// Swap the view controllers' view for a scroll view
NSScrollView *scrollView = [[NSScrollView alloc] initWithFrame:self.view.frame];
scrollView.documentView = self.view;
scrollView.drawsBackground = NO;
self.view = scrollView;
}
I think this answer is not really solving your problem but maybe helps understanding what is up with storyboards and scrollviews. I think Apple still has to fix some storyboard issues. I tried to use a collection view with storyboards, but it's impossible to connect the collectionViewItem in interface builder (which is happening automatically with xibs).
Here is an example with collection views:
Drag and Drop the collection view to a viewController. You will see a collection view and a collectionViewItem appearing. But the collection view item is NOT connected to the collection view. If you try this using IB, nothing happens.
In Identity inspector of IB assign a Soryboard ID. It's a random name which will be used in the code later. Here I am using "MyCollectionView"
If using swift, select your projects name in Module. The code is mostly the same for objC
Connect the collection view to the ViewController, containing the collection view
Do some coding to connect the Collection View item
class IVMyCollectionViewController: NSViewController, NSCollectionViewDelegate {
// manual connections to collection view (which is not working in IB)
#IBOutlet weak var collectionView: NSCollectionView!
class var sharedInstance : IVMyCollectionViewController {
struct Static {
static var instance:IVMyCollectionViewController? = nil
}
if Static.instance != nil {
return Static.instance!
} else {
let bundle = NSBundle.mainBundle()
let infoDict = bundle.infoDictionary!
let sbName = infoDict["NSMainStoryboardFile"] as String
let storyboard = NSStoryboard(name:sbName, bundle:bundle)!
let vcName = "MyCollectionView"
let sbInstance = storyboard.instantiateControllerWithIdentifier(vcName) as IVMyCollectionViewController
Static.instance = sbInstance
return sbInstance
}
}
// implement your controller
}
That means that some UI elements are not properly implemented yet. I would send a bug report to apple. There is still lots of things missing in interface builder.
Right now I would use a mixture of storyboard and xibs to abuse the storyboard in a way like above, by instantiating the connection in the constructor of the controller. You can use the storyboardID to launch views and other views or load from xibs. You can place viewControllers inside a storyboard without connections (segues) to create a pool of views that can be used like xibs. (A viewController is more or less the same like a xib)
// objC
DetailViewController* controller = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
or instantiate using the storyboardID like above.
Try to create a scroll view in storyboard. Create the views which you like to be shown in viewControllers for each view. Your scrollviews view controller should have a connection to the scroll view itself. In the following example the scroll view's outlet is named "self.contentView":
// instantiate a view controller for your scrolling view
self.scrollingViewController = [[ScrollingViewController alloc] initWithNibName:#"ScrollingView" bundle:nil];
// or do the same with storyboards by instantiating view controllers by ID
self.scrollingViewController = [myStoryboard instantiateControllerWithIdentifier:#"MyScrollingViewID"];
// Then set the view from the controller as content view
[self.contentView setDocumentView:self.scrollingViewController.view];
[self.contentView.contentView scrollPoint:NSMakePoint(0., self.scrollingViewController.view.frame.size.height)];
It's exactly like mixing up objective C and swift code. Apple seems to have entered a transition path which was not walked to the end.
In general you should think of View- or WindowControllers in storyboards is the same like a complete xib file. If you would like to use more views, use container views in storyboards. The FilesOwner in xibs is the viewController in storyboards. Container views offer you the ability to create a couple of views attached to a view controller. The segue mechanism is available for containers. I think the scroll view mechanism of OS X is not elegant. I struggled a lot with it, too.
Good luck!
Create the view that will be the document view of the scroll view.
Select that view
Go to Editor > Embed In > Scroll View
Based on this page of Scroll View Programming Guide for Mac.

UINavigationItem doesn't show up

In IB I've put an View Controller with a Table View and a Navigation bar. Because I want to change the actions (and text) on the buttons when the table is being edited, I decided to create the button programatically.
In the implementation file, I've set up the button (copied from another post on Stackoverflow):
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Title";
UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:#"Edit" style:UIBarButtonItemStylePlain target:self action:#selector(EditTable:)];
self.navigationItem.rightBarButtonItem = editButton;
}
But when I run this in the simulator, I don't see the button. Is this the right approach for my goal? Or what am I doing wrong?
Later, I also want to add a Back, Add and Done button.
You probably did not created iboutlet for that navigation bar. Self.navigationItem is a property which is available on any viewcontroller and is applied only if there is a navigationcontroller which manages your viewcontrollers stack. There is no relation to manually created navigationItems..
I assume that either outlet for that navigationbar or going to storyboard, click your viewcontroller and then Editor->Embed In->navigation controller will help you to achieve disered results.

How to connect storyboard to viewcontroller

In the new xcode 5 how do in interface builder you use to have a drop down menu there to connect your storyboard viewcontrollers to your classes how is this done now?
Unless I'm misunderstanding what you're asking, it's still there. Here are the steps to assign a custom view controller class to your view controller:
Choose your view controller in the list of scenes on the left side.
Choose the Identify Inspector on the right side.
Choose the custom view controller class from the Class list.
1、manual creating a Cocoa Class to the project
2、open the story board, draw a view controller from tool box to the storyborad
3、click the controller you draw into the storyboard, and specify the 'Customer Class' to the class you create in step 1
4、if you use XIB, nibName could be the controller name, else if you use StoryBoard, you need set a storyboard id for your controller in your storyboard panel, and you can use the id and the storyboard in your superController when you want to new a controller
// XIB
var viewController = UIViewController(nibName: "ViewController", bundle: nil)
// StoryBoard
var viewController = storyboard.instantiateViewController(withIdentifier: "The-Storyboard-ID-You-Set") as! ViewController

Xcode addSubview: (View Controller) - iPad

Hy,
so i have a question about adding a subview. I'm just created an iPad app which has a home screen i which i should add a subview at some point . But when i use :
NotesMainViewController *openNotes = [[NotesMainViewController alloc]initWithNibName:#"NotesMainViewController" bundle:nil];
[self.view addSubview:openNotes.view];
the main view imports that another view, but the controls on it like UITextField or anything else don't work. So, can please anybody tell me how can I add a view from ViewController to a another view (in that case homeViewController). I have been trying with the addsubview method but it doesn't work.

XCode Storyboard: how to create a segue when the segue trigger is not on storyboard

So I started playing with storyboards in XCode 4.3.2. I started with the Master-Detail application (split view application for iPad). In the detail view (named DetailVC) I have a view where I displayed an array of custom views.
The custom views (named GridView) have a tap gesture recognizer which is supposed to handle the tap event on each custom view. Tapping a GridView pushes a view controller show some search results (named SearchResultsVC).
With GridView created in a separate nib file, and the DetailVC and SearchResultsVC reside in storyboard, how can I create a push segue with destination SearchResultsVC? I just created a segue between DetailVC and SearchResultsVC? Is there someway I can trigger this segue programatically from inside the GridView class when tap gesture is recognized????
In the method where you handle the tap use:
[self performSegueWithIdentifier:#"yourSegueIdentifier" sender:self];
In your StoryBoard control drag from your DetailVC to your SearchResultVC and choose what type of segue you would like. Make sure to name your segue identifier the same as the one in the method above in attributes inspector.
I'm gonna try and improve my answer I messed it up I think:
1) In your DetailVC.h create an instance variable for your GridView like this
IBOutlet UIView * gridView;
also create a getter method and an IBAction for your grid view like this
-(UIView *)gridView;
-(IBAction)myGridGotPressed:(id)sender;
2)Now in your DetailVC.m implement your methods like this
-(UIView *)gridView{
if(!gridView){
[[NSBundle mainBundle] loadNibNamed:#"GridView" owner:self options:nil];
}
return gridView;
}
Also implement your IBAction like this
-(IBAction)myGridGotPressed:(id)sender{
[self performSegueWithIdentifier:#"yourSegueIdentifier" sender:self];
}
3) To make this work you need to change the filesOwner class of your GridView to DetailVC and then hook up the outlets and Actions as normal.
I hope that helps.

Resources