I'm developing a little example for iPad from a UISplitView XCode Template. It's formed by a root controller which is shown in the left of the window and a detail view which is shown in the right.
What I want to achieve is very simple (at least I think so) but I can't find in the documentation the way to do it.
I'd like to substitute the root controller (which appears fixed in the left) with a new controller (for example as response to a event launched when you push a button). I've tried this:
ColorPicker *controlador = [[ColorPicker alloc] initWithNibName:nil bundle:nil];
[self.rootViewController presentModalViewController:controlador animated:YES];
[controlador release];
What happens with that is that the new pushed controller fills the entire window, whereas what I want is that appears fixed at the left with the two columns format that were at the beginning.
You need to set the modalPresentationStyle to an appropriate value,
controlador.modalPresentationStyle = UIModalPresentationCurrentContext;
UIModalPresentationCurrentContext instructs the view controller to appear modally within the frame of the rootViewController.
Use pushViewController:animated instead may fix this. About ModalViewController, check document http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html
Related
I am developing an application with iOS 9 based SDK , this is my first time I am working with Storyboards , I have 20 view controllers, each scene has Next / Previous buttons to go back and forward . I have a huge problem with going forward !. If I move from scene 1 to for example to scene 15 I received memory warning and then application crashes . I have searched and it seems there is method called unwind segue but it seems this is for going back ! it's something like dissMiss method .
I connect each scene with line in Interface Builder :
Here is segue's setting :
I would be grateful if you help me out .
EDITED :
I tried to present a view controller programmatically but result was the same ! .
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
WhatIsDino *vc = (WhatIsDino*)[mainStoryboard instantiateViewControllerWithIdentifier:#"WID"];
[self presentViewController:vc animated:YES completion:nil];
Seems like it's a problem of wrong approach, and not the storyboard.
Let me guess, since before storyboard you used to change your app's rootViewController to the next/previous screen once you tap on the arrow button. So previous screen are released and deallocated from memory once you set a new rootViewController.
And now you're presenting every next view controller modally, which involved creating new UIWindow and loads all the hierarchy of you screen and keeps previous underneath the new one so it holds the memory and you're getting out of memory crash.
Well, you can do rootViewController approach with a storyboard too since it's just another way to manage your screens while development. Storyboard offers additional features like segues, static table view cells, general tint color and so on. [UIStoryboard -instantiateViewControllerWithIdentifier:] is the method you might find interesting.
But I'd rather recommend you to check out the UIPageViewController, it's like a container for the screens. Unfortunately, it cannot have the segues to your scenes (because of the special way segues work) so you have to use -instantiateViewControllerWithIdentifier: method anyway. You can treat inner view controllers of UIPageViewController as you do with rootViewController before.
You can also navigate without segue and Its easy way I think.
If you want to navigate from Class1 to Class 2 then follow these steps.
1) In Class 1, Import Class2.
2) In your button Action, Write this code.
Class2 *next = [self.storyboard instantiateViewControllerWithIdentifier:#"Class2 Identifier name"];
[self.navigationController pushViewController:next animated:YES];
Do not forget to give Identifier name in story board that is "Storyboard ID" in Attribute inspector of particular class.
No need to add Segue,Your storyboard would look clean.
The problem is that you are adding view controller after view controller with modal presentation. That causes each view controller to be added on top of the previous one, and all of them accumulate, using more and more memory.
Using a navigation controller and a push also piles the view controllers on top of each other.
You will have this problem if you use storyboards, nibs, or create the view controllers manually.
If you have a design where the user can move through a large series of view controllers then you probably want to dismiss the previous one before pushing/presenting a new one.
You can probably dismiss the previous view controller without animation and then present the new view controller each time you want to display a new one and avoid the memory issue. i'd have to experiment with it to get the effect I was after, but that's what I would suggest.
I am interested in creating an app that starts with a menu which may possibly contain an options view, then steps from the menu view to a data-item selection view, then to a configuration view, and finally a result view that displays progress or changes. I want to have this process be repeatable like a loop, and have the user be able to jump backwards to a previous view if necessary. Jumping from view to view would of course be a user input / output with a button or something. FYI, I am using Xcode 5.1.1.
What would be the best approach to this? What kind of view controller is going to do the trick? I have heard a lot about navigation controllers, tables, etc.. but am having a hard time figuring out what to use in my case.
Below is a state-diagram similar to what I would like to do...
A UINavigationController should work great as your root view controller. It automatically includes a back button, and you can use the popToRootViewController method to return to the root of the navigation controller. You can set up a navigation controller as your root view controller from the applicationDidFinishLaunching method using this code.
MainMenuViewController *mainMenuViewController = [[MainMenuViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mainMenuViewController;
self.window.rootViewController = navController;
For more information take a look at apples UINavigationController programming guide https://developer.apple.com/library/ios/documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
Each of your other screens may use different types of view controllers depending on their specific needs. If you need to display a list of items, definitely look into a UITableView. Apple's documentation for a UITableViewController can be found here https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewController_Class/Reference/Reference.html
Hi I'm trying navigate to view controller form the navigation view controller with connect using the objects
i want to do by programmatically but its not working its showing the black screen. Please tell me how to resolve this.
- (IBAction)reg:(id)sender {
pollpoliticalViewController *vc2 = [[pollpoliticalViewController alloc] init];
[self.navigationController pushViewController:vc2 animated:YES];
}
The above code i have used to navigate but its giving black color screen its not showing the view controller please tell me where I'm doing wrong.
Thanks.
Nothing is wrong with the above code.
As I understand what you are doing, you have a view controller class called pollpoliticalViewController. My first suggestion would be for you to look into the accepted coding style in Objective-C. You should always capitalise classes. In this instance the class should have been called 'PollPoliticalViewController`. Obviously this is not the source of the problem though.
The problem will be with the view controller itself. In the code for pollpoliticalViewController you are doing something wrong which is not displaying the view.
The view controller may actually be styled inside of a .xib file, in which case you should be initialising the view controller like this:
pollpoliticalViewController *pollVC = [[pollpoliticalViewController alloc] initWithNibName:#"pollpoliticalViewController" bundle:nil];
If the view controller is defined inside of a storyboard, you will have to give the view controller a 'Storyboard ID', for example; 'PollPoliticalVCID'. You then need to initialise it like this (assuming your storyboard is called "MainStoryboard":
pollpoliticalViewController *pollVC = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:#"PollPoliticalVCID"];
EDIT
The storyboard name is found when you open the storyboard, do not select any view controller. Open the Utilities side bar (on the right side of Xcode), select the first item, and you can find the name under Identity and Type. I have included an image.
I am writing an iPhone application where I want to utilize the large popup view, but I don't know what it's called. I have a picure on it.
I mean the middle square that isn't shadowed. It has the title "Köp mer utrymme". I know it's from an iPad, but I'm pretty sure a similiar one exists on the iPhone, for example, the iTunes-store agreements. I looked in Apple's UIKit User Interface Catalog, but I couldn't found it there.
Does anyone know what it's called or how to get it?
On iPad it could be a UIPopoverController with a custom view controller inside it, or a modally presented view controller. You can't use that on iPhone (at least not in the same way, popovers don't exist and modal views are full screen).
On iPhone you could use a UIAlertView, or you could search github / cocoacontrols for a suitable 3rd party implementation.
The view on the picture is presented modally. When presenting a view modally, you can customize the presentstion style. The default style is UIModalPresentationFullscreen, but the style in the picture is UIModalPresentationFormSheet.
To present a view controller in that style, you first create an instance of the view controller and then set its style.
MyViewController *vc = [[MyViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:vc animated:YES completion:nil];
Note that isn't possible to change the presentation style for iPhone. (I must have imagined that the iTunes-store agreement wasn't fullscreen.)
Use KGModal.h and KGModal.m class. For a PopVieController is is best ....and easy to make and add control over it and no need to set frame for orientation ....
Find these 2 Class (KGModal.h and KGModal.m)...
Can anyone tell me what the best way to do the following is in Xcode (iPhone).
I have a main navigation screen with some buttons on it. When the user clicks any of the buttons they are taken to a sub-navigation screen with more option buttons on it. Here they click whichever button and are taken to a list of options. Clicking on any list option will display a screen with some information to the user. Each one of these screen ( no matter what section of the app you're in) will look the same. Only text and images on these screens will change.
I have enclosed a diagram that might explain it better. What is the best way to handle this in Xcode? I have tried doing it all in Stroyboard as I'm new to Objective C but just the sheer amount of individual pages is slowing my machine down to a crawl. So a rethink is required.
I am also doing an Android version of this app and I'm using Fragments for this. Can anyone please help?
EDIT: Just got to my devel machine and this is what I have been doing so far. I realise now this is the complete wrong way to do it. I have created a view controller for each "screen" if you like.
So I just create one view controller for all "screen" of e.g. Individual Page as per diagram and then add the text dynamically depending on what screen is selected? Can anyone point me in the direction of a tutorial or what I need to be searching for? I have no idea where to start with this using Xcode.
If the elements of the view are the same (and only the actual text and images are changing), all you need to do in your storyboard is to create one view controller that will have all these ui elements, from code you can then set it up depending on the content that you want to display in it (depending on what the user clicked in the previous view controller).
EDIT:
Not sure why it was downvoted, but i'll be more clear. Clearly that one view controller is not ALL you need to do in the storyboard. It's all you need to do ON the storyboard related to all the elements called Page in the diagram. Then you would have to link it to a PageViewController class and to all the outlets related to configurable UI elements and in the code of your prepareForSegue: method from the Secondary Nav Screen View Controller you would have to configure it accordingly to what you want to show.
Here you can find a good beginner's tutorial, along with many other good tutorials. What you're probably missing is that you also need to tell the storyboard what class the view controller is and how to connect stuff like labels and imageviews to the actual code so that you can configure them appropriately.
I.E.
From what you're describing, it sounds like you want a UINavigationController as your app's window's rootViewController and to show your screens inside that. You want to create four controller classes:
HMMainScreenController
HMSecondaryScreenController
HMListScreenController
HMPageController
Hopefully it's obvious what would be in each. You'd set up your window in your app delegate like this:
HMMainScreenController *mainController = [[HMMainScreenController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mainController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
When the user taps a button in your main controller, you'd do this:
HMSecondaryScreenController *secondaryController = [[HMSecondaryScreenController alloc] init];
// configure it appropriately
[self.navigationController pushViewController:secondaryController];
and so on for your list and page controllers.