How to temporarily hide UIPopoverController - objective-c

I have a UIPopoverController which i want to drag items from it and drop them on another view.
I implemented the mechanism for Drag & Drop from a popover but i want it to be even better: while you dragging, i think the popover should be hidden so you could drop items right underneath it.
Since UIPopoverController is not a "Classic" view controller i dont know how to hide it temporarily without dismissing it irreversibly.
BUT since UIPopoverController presents something on the screen, there got to be a "View" somewhere inside that popover controller that i can hide and show...
Any suggestions?

Would it work to "hold into" the view controller in the popover in some way (like an ivar of the object that presents the popover) and then just dismiss the popover? That way, the view controller will still be there and when you want to show it again, you can.

Related

Create back button

How do I create a custom back button on one of my storyboards, when I do a segue and I say push it creates a back button on Mac with but when I do a modal or model it does not create a back button?
Modally presented view controllers do not automatically get close buttons.
self.navigationController.leftBarButtonItem = ...
A pushed view controller will automatically create a back button if the navigation controller is shown.
You will have to create your own back button. In the view controller that you have presented via the modal transition, you have to put a toolbar on it. Put it at the top and if using autolayout set the constraints top, both sides and height. Then place a barbuttonitem in the toolbar. You can select a system button like done or cancel. Make sure the new view controller is the class that you created. Now you can control drag from the barbuttonitem to your .h file and connect an IBAction. Call it dismiss or something like that. In that method call [self dismiss viewcontroller:animated completion:nil]. This will bring you back to the original view controller. I am not a my computer right now so I am not sure the exact wording of the dismiss method, but it will auto fill for you. Good luck.
As Douglas explained, you need to create property of the button (UIButton or BarButtonItem) and in the viewcontroller .m file connect
- (IBAction)backButton:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
with the button. This will dismiss the current view controller and bring you back to the previous one :)

How to modify objects within a modal view?

I have an app with several views. Taking into consideration the large main view, called MyView1, it is controlled by MyView1Controller. Within MyView1, there is a button that causes a modal segue to another view, whose controller is also MyView1Controller. This modal view has a couple UILabels, and a button that terminate the modal view, bringing the user back to MainView1.
Here is the problem... Let's say in my modal view there is a UILabel called sampleLabel. While in MyView1, a button is pressed, which executes the code:
sampleLabel.text = #"changed";
Since the UILabel named sampleLabel is not on screen for MyView1, and instead is part of the modal view from MyView1, nothing happens. However, when I click on the button to view the modal view from MyView1, the UILabel hasn't changed.
This is even more puzzling since the main MyView1 and the modal view that segues off of MyView1 are controlled by the same view controller, MyView1Controller.
Can someone please tell me how I can make code that executes during the user's interaction with MyView1 change things in the modal view, so that when they press the button and segue to the modal view, the UILabel's have already been changed?
Thanks!
First of all, Apple recommends (and it makes life a lot easier) to have one view controller for each view. So you should have a second view controller. In the second view controller you would have a property called sampleLabel. In the first view controller you could use different methods to set the sampleLabel.text. I would probably create a separate sampleLabelText property in the first view controller (could be an NSString *) and set it to the text you want when the user presses a button. Then in your
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
you would get your second view controller and set its property like this:
SecondViewController *svc = [segue destinationViewController];
svc.sampleLabel.text = self.sampleLabelText;
That's it. Hope this helps.
So I have had a similar issue that I resolved through 'delegation' but not through a segue schema. Here is a link to the stackoverflow question and my answer. Delegation
Hopefully this gets you going in the right path. Instead of modally presenting a view, I push a new viewcontroller onto a navigation stack but the same answer should apply, hopefully :P

Add a UINavigationBar and UIToolbar to modal UITableViewController

I'm creating an app that has a similar layout as the Apple Contacts app. I have created a UITableViewController and embedded it in a UINavigationController using a Storyboard. I then have an add button that opens a UITableViewController in a modal view. I have added a top bar to this view using the storyboard and it works pretty good. The problem is that it scrolls away when you scroll in the table. It should stick to the top.
Do I need to embed this modal UITableViewController in a UINavigationController as well to get the "sticky top bar"?
What's the preferred way of doing this? Just embed using the storyboard or just create one "on the fly" in the prepareForSegue method?
EDIT
I ended up just embedding the modal UITableViewControllers in UINavigationControllers using Storyboard.
Yes, you do need a UINavigationController that contains the UITableViewController to get what you aim for.
Personally, I would prefer creating it "on the fly" as you call it. But that is a matter of taste.
The way to do it in the storyboard is to have your modal view controller be a UIViewController rather than a UITableViewController. Add a view controller, then drag in a tool bar, and position it at the top. Then add a table view to take up the rest of the space below the tool bar. This will work correctly without scrolling with the table view.

How to Notify RootViewController of View Changes

I have added a UIButton to a toolbar that is only accessible via the RootViewController (which has a navigation bar and toolbar) of my app. When navigating to another view, I hide the UIButton, but when I go back to the initial screen (a map view) the UIButton remains hidden and I must unhide it. Since it is the RootViewController I am doing this in, viewWillAppear is not called, so I cannot use that method.
I am wondering if there is any way the RootViewController knows when a view is being popped off the navigationController stack, if so, how would you suggest I check for this? Is there any way you would recommend implementing this?
Thanks in advance!
if your app using UINavigationController for navigation then viewWillAppear will obviously called

popViewController problem in tableViewController

In my app delegate I have a navigationController property.
In my first view I have some buttons and tapping them will make another view appear when it is pushed on navController.
In this new view there is another button to open a UITableViewController by pushing it on the navController.
The problem is in the last view, UITableViewController, in fact in viewDidLoad, if I have no data, I try to pop it off the navigationController but my app crashes.
However, if I connect the pop to a button it works great.
I reference my app delegate instance in order to popViewControllerAnimated:, so what is the problem?
I'm not sure what's wrong with the code, can you post your viewDidLoad method?
Also, is it possible to check whether your table will have data BEFORE you push the tableView onto the nav stack? That would be a much cleaner UI, rather than showing and then immediately popping a view. If there is no data, disable the button that launches the table view.