Calling multiple views from Uipopovercontroller list view contents - ios

How can I call individual view controllers when I tap each row from my Pop Over List View in the most effective way? Meaning, I don't have to recode to build the Pop Over List View component in each of the individual view controllers, they can sort of share it like a navigation tool.
What I Have Built
I have built the pop over view controller list on my Main View Controller.
This is the 1st view that gets loaded when appDidFinishLaunching is executed.
So, when we run the app, this is what we get:
Link to screenshot of the Pop Over List View:
http://s14.postimage.org/63k567vtd/image.png
For each row in the above Pop Over list, I have a method where I can put in the codes to:
1. Identify which row was selected
2. Based on the row selected, do any action, like NSLog and stuff
3. All this codes sit in the Main View Controller
The Requirement
I am building a demo app, so all data is dummy data at the moment.
I need to call individual View Controller when each of the row in the Pop Over list is tapped.
Each of the View Controllers, will have their own set of data, own set of UI objects, its own XIB file.
So, if user taps on Applications, it must bring up the Applications XIB file and its functionality, followed by any navigations from here. If Application xib has a button that launches another view, this functionality should be in place too.
However, they all must have the same top Navigation Bar with the Pop Over list button, so user can tap that button and see the Pop Over list anytime in the app.
Please share your view.
Thank you.

I suggest looking in to UISplitViewController. It is a component built by Apple to manage what it looks like you are trying to accomplish. Essentially, you set it up with 2 view controllers; the first (called the "master"), would be your table view. The second (called "detail") would be the view controller that gets switched out.
Once you explore it a little and are comfortable with the terminology, here's the general advice:
Inside the master table view controller's didSelectRowAtIndexPath: method, instantiate the appropriate view controller (based on the indexPath), and set it as the detail view controller, like this:
- (void)tableView:tableView didSelectRowAtIndexPath:indexPath {
UIViewController *newDetailVC = // make and configure a new VC based on indexPath
self.splitViewController.viewControllers = [NSArray arrayWithObjects: self, newDetailVC, nil]];
}
Here are the appropriate links:
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UISplitViewController_class/Reference/Reference.html#//apple_ref/occ/cl/UISplitViewController
and further (the later sections of): http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html%23

Related

UzysSlideMenu: how to use several view controllers?

I just came across a slide-in menu I really like: https://github.com/uzysjung/UzysSlideMenu
I would like to use this menu for an application that uses several view controllers (UIViewControllers and UINavigationControllers).
In Xcode, I created a single view application and made the view controller (MenuViewController) show the menu, like the creator did in his example project. I added more view controllers to the storyboard and connected them via segues to the MenuViewController. Upon selecting a menu item, these segues are triggered and the selected view is shown - so far so good.
But now, I run into the following problem:
All my view controllers are shown in full screen. That means that VCs that get segue'd in the viewport don't show the menu, because it's just not implemented there. I could put the menu in every VC, but that doesn't seem to be the right way to do it (even if I use some custom delegate method that every controller calls, like putMenuInViewController:(UIViewController *)target). I think I need something like a global singleton for the menu and make it appear in every view controller, but I have absolutely no idea on how to it or what to google for.
Any points into the right direction are greatly appreciated :)
I think you need to implement one root view controller with this menu as singleton, and add other view controller as child view controller to it.
I wrote a post about it, you can find it here:http://antrix1989.blogspot.com/2013/09/uiviewcontroller-as-singleton.html

How make static view on any viewcontroller in Xcode?

I Have interesting question.
I have two screens, I need that would be the third screen elements (buttons, label) are static and do not change when you move from one screen to another. .
So MAIN DISPLAY 1 will be change, DISPLAY 2 too , but button and others(label for example) need be static.
Big Thanks for all help, sorry i don't have any code with this problem. Because i don't know how this make...
Ok, so if you have a UI that won't change it's content you have to consider the following:
If the user can navigate from one screen to another, then you will have to create multiple view controllers(it can be done in other ways but this is the easiest and best way to doit) that will have their own UI, that can be easily created in storyboards like this:
Create a new project that use storyboars (you can use the Xcode templates that support your needs)
In your generated storyboard, drag and drop a new UINavigationController, and in the Attributes inspector check the Is initial view controller
Drag another UIViewController into your storyboard, select your navigation controller, hold right click and drag to the newly added view controller, a popup will appear and from that popup select root view controller. Now the newly added view controller will be the first view that the app will display. On this view controller add your UI elements (buttons, labels, etc). If you want another screen to be shown when a user taps on a button, drag another view controller and select the button from which you want to display the next screen, hold right click drag to the newly added view controller, from the popup select push. Now when the user tap on the button the next view controller will be shown and as a bonus because you use iOS, the system will create a back button so that you can go back to your first view controller.
Ok, this is the a basic tutorial from which you can start and expand, but for that you will have to read more, spend nights on google/SO to find solutions, you will learn apple docs by heart and other things that are required so that you can be a great iOS developer.
My the iOS force be with you and Steve Jobs watch your steps.
This is off the top of my head:
you could put a view into your uiwindow and place your static elements there, and then give a transparent background to display1 and display2. then you can have the two displays forward their touches to the background elements to have actions on the buttons. im sorry i dont have any code, but i never tried that ;)
A much better way is to instantiate your ViewController like so:
this.NavigationController.PresentModalViewController (StaticViewController.staticViewController, true);
Then inside your instantiated View Controller you setup a static variable that holds that instance of the View Controller:
public static StaticViewController staticViewController;
When the Static View Controller fires up for the first time:
staticViewController = this;
Now in the future when you fire up the Static View Controller (from wherever in your app) you can check to see if the StaticViewController.staticViewController variable is null or not.
Use simple if else logic to load it up accordingly:
if (StaticViewController.staticViewController == null) {
StaticViewController.staticViewController staticViewController = this.Storyboard.InstantiateViewController ("StaticViewController") as StaticViewController;
this.NavigationController.PresentModalViewController (StaticViewController.staticViewController, true);
} else {
if(!StaticViewController.staticViewController.IsBeingPresented) //safeguard against click happy users
this.NavigationController.PresentModalViewController (StaticViewController.staticViewController, true);
}
You should add the static views to your UINavigationController or whatever controller you are using for managing multiple controllers.

iPhone tableview drop-down menu

I have a view controller with a table view in it and several buttons. I would like to add an additional tableview on top of the view like this (or at least what it would look like if anybody wanted to be my friend :-)):
I don't want to just add this as a subview (like here or here)enter link description here since I don't want to check which table view is being used in my tableview delegate and datasource methods. I would rather use a separate view controller.
I don't want to use a picker because I need to display a bit of info with the items in the list.
I have no problem creating the view with the corresponding controller, but how do I add it on top of the current view, just hiding portions of it?
Thanks!
Apple has a sample code of TableView which deals with this issue. https://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40010139
Above URL is the link to download the sample code from Apple developer library.
Hope it helps.
This might be overly simplistic for your application, but I have found it to be effective when I have had to do something similar.
You can add this 'drop down menu' view controller's view to the main UIWindow of the entire application. You can add a UIGestureRecognizer on the window as well. If the tap is outside of the view, make it fade away and remove it from the view hierarchy.
Initially I simply added logic in my tableview datasource and delegate methods to destingwish between the two tableviews (as suggested by Scott Bossak above. But I have since switched to building my two views in storyboard and adding their view controllers as usual. However, to present the second table view I instanciate it like so:
SecondTableViewContriller *secondTVC = [self.storyboard instanciateViewControllerWithIdentifier:#"secondTVC"];
then add it as a child view controller:
[self addChildViewController: secondVC];
[secondVC didMoveToParentViewController:self];
I then implemented a protocol to pass the information back to the parent view controller once a row has been selected.

Dismissing a view makes losing it all values... viewWillAppear as a cure?

I have a basic modal view system.
My app loads the UI base in which there are 2 buttons presenting 2 other views.
In those views, a dismiss button.
Everything works fine.
BUT, in one of the 2 modal views, I have a bunch of UISlider & UISwitch.
I want them to retain their values but the dismiss loses them: as soon as I trigger the button to show the view containing the UI elements, this view is shown with all values for all elements as I put initially in the xib.
should I store all values in variables, then in viewWillAppear I could "recall" them ?
would you advice me another strategy ?
Yes, your proposed approach is exactly the right sort of thing. But be careful; viewWillAppear can be called for many reasons; make sure you're only doing this when the view controller is coming into existence and showing the view for the first time.
NSUserDefaults can be an excellent place to store globally needed info like this. In viewWillDisappear, store the desired state info (values of the sliders and switches) in defaults. Then retrieve them the next time the view is about to appear.
When you create the modal view you are creating a new instance of the modalViewController an the modalView. This new instance knows nothing about any other instance. There are a few ways you can retain the information from previous iterations of these modal view controllers.
How I would do it:
Set up place holders in your main view and pass the values that the user selects back to the main view via a protocol and delegate setup. Then when you segue to the modal view you can load those variables in before displaying the modal view.
So let's say you have a dictionary with all of the values: {slider = YES, someValue=10,...} Create that dictionary in the main view controller, the first one that opens, and place some default values in it.
In your modal view controllers create the same dictionary as a property.
Create a protocol in your modal view controller with a method that is something like
- (void) doneEditing:(NSDictionary *)values
Set up your first view as the delegate for the modal view controller and in the implementation of doneEditing copy the values to the dictionary that is present in the first view before popping the modal view.
When the first view is ready to present the modal view again, copy the values to the dictionary property of the modal view before presenting it.
I hope this gets you headed in the right direction. It's important to remember that each time you segue or create and present a modal view you are creating a brand new instance of that view, it knows nothing about the previous instance at all unless you tell it something about it.

TableView index from rootcontroller to detailcontroller (UINavigationController)

My root view is a grouped tableview. When the user selects a row, i want to be able to retain which row was selected to give to the detailcontroller for loading the correct data.
All the navigation is working fine, I just don't want to have to create a global variable to just retain the index. Is there a built in method for the navcontroller or something?
You can either set a property in you detail view controller before it is pushed giving info about the row selected so it can influence the behaviour of the detail view controller, or it is possible to access the parent view controller directly from the detail view controller with:
#property(nonatomic, readonly) UIViewController *parentViewController
I prefer the first option - you can write a custom init... method, to supply the data for the detail view controller when it's created.
There isn't a builtin way as such, you should try and make the view controllers de-coupled as possible so they can be re-used and are resistent to changes elsewhere in the app.
This is a useful quote from the View Controller Programming Guide for iOS:
With the exception of view controllers managing leaf data, each custom view controller must provide a way for the user to navigate to the next level of the data hierarchy. A view controller that displays a list of items can use taps in a given table cell to display the next level of data. For example, when a user selects a photo album from the top-level list, the Photos application creates a new photo album view controller. The new view controller is initialized with enough information about the album for it to present the relevant photos.
I wanted to follow up with how I ended up coding this. I'm still somewhat new to Obj-C, so some concepts I haven't dealt with or come across, so if this is old hat, sorry.
You can create your data element in the child controller and pass the data 1 for 1 directly to that element by accessing its property.
ParentController.h
NSDictionary *myData;
ChildController.h
NSDictionary *childData;
// This would get called in the parent controller where appropriate
// but before the child controller is presented
ChildController.childData = myData;
This is obviously very stripped down, but the idea works. Just take your data and pass it to the property before calling it and it will be there once the child view is presented. Hope this helps.

Resources