I am trying to build an fairly simple iPad app that requires me to navigate through multiple views. What I want to do is have some sort of main menu view with multiple buttons on it, and when you click one of the buttons the new view appears and then you work with that. I'm new to iPad development, so I have a few questions about the best way to get this done.
1) If I build the views in Interface Builder, how do I make them aware of each other in Xcode? I can't seem to figure out what I need to do in order to code a button to say "Open View 'Foo'"
2) When I open the views, how should I be adding them in relation to the main menu view? Should I add the new view as a subview of the main menu view, or should I close the main menu view, open the new view, and then reopen the main menu upon closing the first view? I imagine both ways are possible, but are there any performance implications I should be aware of?
Thanks,
Mike
I'm making an assumption that it's more or less the same between iPhone and iPad. I haven't started iPad development yet.
You make view controllers aware of each other by importing their headers in your implementation files
FirstViewController.m
#import "SecondViewController.h"
If you're going for a navigation-style app, you should embed your top level view controller in a navigation controller, then you advance to the next one by calling
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
//set any properties
[self.navigationController pushViewController:secondVC animated:YES];
[secondVC release];
Related
I'm sure I'm asking a simple question but I've only just started coding... so take pity on me!
I'm trying to figure out how to connect buttons (actions) to the viewController.swift from a modal/popover segue (I think the solution is the class but whenever I change it I get an error).
Eg.
In the storyboard, on the viewController interface, I have a button for sharing files. When I click it, a popover segue appears with two buttons on it, one for Fb one for Twitter, but I can't connect any actions from them to the viewController.swift
In another project I made a Google+ login and connected it to a modal segue but I couldn't make that work either.
Is segue the wrong thing to use?
Thanks for your help!
Marie
Your question would be easier to answer if you'd provide the actual error you're getting when you try to change the class.
It sounds like you're trying to connect the popover's buttons to actions in the presenting view controller (that is, the view controller that presented the popover), rather than the view controller of the popover itself. If that's the case, then that's the problem. You can only connect your buttons directly to actions available in the current scene.
This means you need a custom class for the presenting view controller (the one with the button that segues to the popover controller) and one for your popover. Set each scene view controller's classes to the appropriate custom classes you created (which must be a subclass of NSViewController or one of its subclasses or you won't be able to set the class name in IB) and you should be able to drag connections.
I often make use of views in interface builder that live outside of the viewcontroller hierarchy (see screen grab below for simple example).
Before upgrading to Xcode5 I could get this view to appear on the storyboard by writing an IBAction outlet and dragging a connection from the code to the view in the storyboard.
If you paused over the button for a moment it would flash and then open up as a view on the storyboard that is then a lot easier to work with.
Since upgrading this function no longer seems available. Has anyone found out how to get these views to appear on the storyboard?
Edit:
Using the temporary viewcontroller as described in this answer seems one approach, although fiddly since you need to move the UIView stack between viewcontrollers each time you want to edit the layout. Using a separate XIB is starting to seem like the sanest approach.
https://stackoverflow.com/a/13713385/1060154
Finally, we get this back in Xcode 7.
Hallelu!
I'm new to programming IOS and I'm creating a small App for our College. This app consists of a main view that has a couple of buttons to open different things (Map, Welcome message from the Dean, Intro video, etc...). One of these buttons will open a table view that will show our 5 campuses. When they select a campus it will open a UIWebView that shows the information about that campus.
My problem is that I was able to add a nib to my project and place a tableview object in that nib. It displays, but I,m not able to get the navigation bar or navigation button to show.
Would you have any site or suggestions?
Thanks
Ren
You should try using an Navigation Controller. When you connect the other views to it, it will automatically add the bar and the button.
Good luck!
I started an iPhone App with the Xcode template for UITabBarController, which created a couple of default UIViews (MainWindow, FirstView and SecondView).
The MainWindow xib shows the tabbar itself, which can be configured there.
FirstView and SecondView have an unselectable UITabBar anchored to the bottom, which is ostensibly to show the relationship to MainWindow.
Note that I've created many new views that are part of the main UITabBar and they work fine, but they don't show that UITabBar at the bottom in Interface Builder.
My question is, how does that work, and how can I create a new view such that it will show that unselectable UITabBar at the bottom?
What you're seeing is simply Interface Builder's "simulated metrics" and it shouldn't actually have any bearing on the app's behavior. But this is how you can change it:
I have a question, I do some iphone application and now I want to do a little mac application.
From a clean application I add a button on MainMenu xib, than I add a NSViewController to MainMenu (from IB) with one Action.
I create a new NSViewController (FirstViewController) with a nib file and a button.
Now I want only to create a function to push FirstController from MainMenu and a simple function to push MainMenu from FirstController.
something like this
ViewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController: ViewController animated:YES];
How can I do it???
I think you're trying to bring an iOS-style interface to MacOS X, and that won't work in many cases. The MacOS X user interface is very different from that of iOS.
iOS apps are limited to a single (and often small) window, and users generally do one thing at a time. The navigation interface standardizes the way that users drill down through different parts of a task so that the journey is predictable. The interface is very modal in the sense that the user is constantly navigating between different parts of the app, and user actions are often linked to the part of the app that's active.
The desktop, on the other hand, has plenty of screen space and allows multiple windows. Desktop apps should be modeless -- a user doesn't navigate through the app, but sees the whole thing laid out before him or her. As much as possible, the user should be able to perform any action at any time.
For these reasons, there is no navigation controller in Cocoa similar to Cocoa Touch's UINavigationController. If you can tell us more about the tasks that your two view controllers manage, perhaps someone here will help you think of ways to translate that better to the expected desktop experience.
Here apple discusses the migrating iOS to OS X strategies. Your scenario is also discussed here:
For example, AppKit uses the NSBrowser class to manage the display of
hierarchical information; in contrast, an iOS app would use navigation
controllers.
And NSBrowser can be seen in use here with the output as shown in the attached image.