Xcode addSubview: (View Controller) - iPad - xcode

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.

Related

side menu with UITabBarController and storyboards ios

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];

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.

NSPopover switch view

I have a popover menulet and it's contentViewController is some NSViewController. Everything fine here. The problem that I have is that I really don't understand how to change the View. I wanna load another view, and this is what I tried:
popover = [[NextViewController alloc]initWithNibName:#"NextViewController" bundle:nil];
[self.view addSubview:[popover view]];
And this works, new view is shown - but if I click on any button on that view I get error: unrecognized selector sent to instance. Why am I getting this error? Why this new view is not responding?
Please help me understand what I need to do, how to change the view on NSPopover?
I've managed to solve my problem, It turn out to be quite easy:
[self.view setSubviews:[NSArray array]]; //remove all previous subviews
[self.view addSubview:[popover view]];

Setting view in NSSplitView not working

Please excuse my ignorance, I'm coming from iOS to Mac programming. I have two nibs. One is the main window with the split view. The nib contains a navigationController view I created. I'm trying to replace the right pane of the split view (navigationView) with this view. When the application first launches, navigationView is just a custom view in interface builder.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NavigationController *navController = [[NavigationController alloc]
initWithNibName:#"NavigationController"
bundle:[NSBundle mainBundle]];
navigationView = navController.view;
}
This doesn't seem to do anything. I tried adding the navController.view as a subview, and that at least gets it showing up, but it is placed very oddly. Any suggestions? Thanks!
You will definitely have to add the views you want in the NSSplitView as a subviews of the NSSplitView. You'll need to provide more information about what happens after that.
There's lots of sample code on Apple's website and many of them use NSSplitViews.

ios4 - Load new view on clicking a button

I am currently using XCode 3.2.3 and iOS4. I'm working on an app that simply starts with one screen and on a button click moves to the next.
I have gone thorugh the ViewController programming guide and a post here.
What I am doing is very similar to whats happening on the post. So let me explain the steps, I followed:
In IB, drag and drop, a View from the library into the editor. I renamed the new UIView to myView.
In my AppControllerDelegate, I added the new view "myView" as a property of the view controller (File's Owner). I synthesized it as well in the implementation.
Now, in the implementation of the ViewController, within the button pressed action handler, I wrote the following lines of code:
[self.view addSubView: myView];
On clicking the button however, I do not see a new screen or my new view. However if I do this, I get a new screen or new view:
UIView *anotherView = [[UIView alloc] initWithFrame:self.view.frame];
[self.view addSubView: anotherView];
I do know that the best way is to do it with separate NIBs for each UIView. However, I am new to iPhone development and have not explored that path as yet.
My question: What am I missing upto step 3?
One way you could be able to do it is by trying it this way
myView = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle: [NSBundle mainBundle]];
[self.view addSubview: myView.view];
Try that and see if it is working.. if yours is a view based project then instead of [self.view addSubview: myView.view], just give [self.view addSubview : myView];

Resources