I have two view controller which Controller A and B. A controller displaying some info on screen. On top right of A screen I have a UIButton on click of button I want to show a help screen which will have some labels & when I touch the help screen it should go away.
I can do it by adding a view on top of all view & hide, show it. But I want to know how can I show HelpScreenViewController as a semitransparent view controller on top of first view controller on click of UIButton. When I tap on HelpScreenViewController it should go away.
EDIT:
I have added below code but does not work
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"TopOverVc"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:NO completion:nil];
Thanks in advance.
For what you described, you dont need a ViewController to contain the 'TopOver' view. A normal UIView would be better. Place that within your first ViewController, in interface builder. Drag it into your A ViewController class, along with the button. When the button is clicked, just show/hide your view containing the info you need.
You can use the containerView control and you can add the childViewController for it. You can use this as overlay by doing the background colors transparent as your needs.
This article may help help you http://spin.atomicobject.com/2015/07/21/ios-container-views/
One more thing, you can set this containerview hide/visible as you need.
Related
I'm looking to replicate the basic functionality of the Stores finder in the new Starbucks app (MapView with a tableview bellow it) but am unsure as to how I would go about implementing the sliding aspect of presenting the view
The main aspect of the functionality I am trying to replicate is the ability to present the modal and have it dismissible by sliding it down off the screen as I am able to replicate the Map + Table view already
https://www.cocoacontrols.com/controls/kipulltoreveal Just make a custom cell and you can make it identical.
Well from the Gif you posted, It seems that Starbucks just present the view controller modally which is very easy to do.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
YourViewController *yourVC= (YourViewController *)
[storyboard instantiateViewControllerWithIdentifier:#"yourView"];
[self presentViewController:yourVC animated:YES completion:nil];
As for dissmissing the view you would need to set ViewController's interactivePopGestureRecognizer delegate to self and then handle its behavior in -gestureRecognizerShouldBegin:
That is, when you want the built-in pop gesture (– popViewControllerAnimated:) to fire, you must return YES from this method. The same goes for your custom gestures - you have to figure out which recognizer you are dealing with.
My thought is this is just a viewcontroller containing 2 basic views:
The background view including tabs and your personal info page which is below tabs.
A table view occupying the whole screen.
section 0: header: empty header / no cells
section 1: header: search bar / 1st cell: mapView trespassing its bounds to cover section header / other cells: locations
Whenever you scroll down 'too much' they defined. They do animation to hide the tableview
To make it looks like a modal view, they make the map corner rounded.
I have presented a tableview controller on a view controller.That tableview comes as full screen on view controller but I do not want to present the tableview on full screen.Is there any way to manage the size of presented vie controller. And the second problem is that i want to present a vie controller which have some label , some text boxes and a table view. Please help
IF you are using iphone device then the viewcontroller will occupy
the full screen .
If the device is iPad,then u can use modalPresentStyle.
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:yourVC];
navController.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentViewController:navController animated:YES completion:nil];
For iPhone ,add the views like UILabel,UITableview to the mainView and present it.
The UITableViewController is used when the table view is the main view of the controller.
In your case it seems more appropriate to use a normal (subclass of) UIViewController and add a UITableView as one of its sub views.
Then you can resize it as you prefer and add other elements (labels...) as additional subviews.
Usually in this configuration you may want to set the view controller as the delegate and dataSource of the table view.
Does this answer also your first question?
You could not change the size of the presented view controller. Another way to do it is by adding it as childViewController by:
[self.view addSubview:tableViewController.view];
[self addChildViewController:tableView];
Then you can change the size of the tableViewController as you wish.
I am looking for a way to implement this kind of popover.
Are there basic iOS commands to generate this style instead of the usual Arrow + Border popover that we see in XCode? Or is there an API to do this kind of thing.
The popover is coming up from the bottom of the screen, just like in the App Store animation sometimes.
Thank you
What you want to do is create a custom UIVIewController with the modal presentation style set to UIModalPresentationFormSheet:
YourCustomViewController *customVC = [[YourCustomViewController alloc] initWithNib:#"YourCustomViewController" bundle:nil];
customVC.modalPresentationStyle = UIModalPresentationFormSheet;
[self self presentViewController:customVC animated:YES completion:nil];
You will also have to create a toolbar and format it correctly with a "close" or "done" button that will dismiss the view controller
I have a UIViewController called DashBoardViewController that acts as delegate for a UITabBar. In its xib I have placed a UITabBar with 3 UITabBarItem.
Each of these items activate a different View Controller, let's call them ViewController1, ViewController2, ViewController3
DashBoardViewController is supposed to show ViewController1 and select the first bar on loading, so in my initWithNibName I have what follows:
...
ViewController1* vc = [[ViewController1 alloc] initWithNibName:#"ViewController1" bundle:nil];
[self.view addSubview:vc.view];
self.currentViewController = vc;
...
I implement the UITabBarDelegate having something as follows:
if (item == viewController1Item) {
ViewController2 *vc2 = [self.childrenControllers objectAtIndex:1];
[self.currentViewController.view removeFromSuperview];
[self.view addSubview:vc2.view];
self.currentViewController = vc2;
} ...
Problem
The View Controller in the first UITabBarItem always works as expected, extending it to the full size of thew view.
However, in the second and following tabs, this doesn't happen: the view doesn't extends. This shows if, for example, I align a tab with the bottom in the ViewController2 XIB: this will not be at the bottom when viewed inside the UITabBarItem.
Note
Please note that this is not related to the XIB: if I invert ViewController1 and ViewController2, it will be ViewController1 the one failing to extend. It's related to the UITabBarItem.
Ideas
Possibly, this depends by the way I addSubview when I call the DashBoardViewController's initWithNibName. But I can't find a way to explain this.
Other details
All the XIB are set with "Size = none".
I can't really speak to the way you have your XIB setup without seeing it, but I can make a couple of suggestions.
The behaviour that you're trying to implement by removing & adding subviews to DashBoardViewController should really be handled by a UITabBarController. This provides a UITabBar, a view for your content and handles the logic of switching between UIViewControllers while keeping layout sane and being part of the SDK.
If for some reason you can't, or don't want to use a UITabBarController, I'd suggest implementing a viewWillLayoutSubviews method on your DashBoardViewController, like so:
- (void)viewWillLayoutSubviews
{
if( self.currentViewController )
{
self.currentViewController.view.frame = self.view.bounds;
}
}
Maybe also try adding the self.currentViewController.view.frame = self.view.bounds; line after you've swapped ViewControllers too, for good measure. This will make sure that the frame of your current ViewController's view is always sized to fill the bounds of DashBoardViewController's view.
This isn't the 'Proper' way to do it though, I'd really recommend using a UITabBarController if you can, since you don't know how much else of UITabBarController you'll end up re-implementing if you start rolling your own controller.
Any further problems will most probably be to do with the internal layout of your sub-ViewControllers, rather than their size / position in DashBoardViewController's view.
On your XIB File make sure that your set the flexible height to stick to top and bottom, this way the UITableView will always have the same height as the 4" display
I am implementing a WEPopoverController and would like to set the title and put a button on top of the popover. Is it possible to do that with this controller?
This is what I have so far. I am loading TableViewController into the popup.
I tried to set self.title=#"title"; in the tableviewcontroller's viewdidload but that didn't help. I only see the tableview with borders inside.
I tried to create a tableview controller in storyboard and programmatically load into the popup but i couldn't resize it. Plus i am not sure if that would be good programming practice.
This is how i load the popuptableview. Would it be easier to use a UIViewController? I don't really need the tableview.
PopUpTableViewController *popUpTable = [[PopUpTableViewController alloc]initWithStyle:UITableViewStylePlain];
// TestViewController *testView = [[TestViewController alloc]init];
self.popoverSettingsController = [[WEPopoverController alloc]initWithContentViewController:popUpTable];
[self.popoverSettingsController presentPopoverFromRect:frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp
animated:YES];
I looked through the preference options but didn't see anything about title. Would i have to resize the container?
You should create a navigation controller with your popUpTable as root view controller and then use the navigation controller as the content view controller for the pop over.
If the above is done, then your logic of self.title inside popUpTable and creating bar button item will work!