I am creating a tableView on my iPad app where one of the cells has a UIButton titled "Edit notes". I would like a view to pop up over the screen containing a "textfield" and the keyboard, not a new view/push. Prefferably not even covering the whole screen. I guess I am looking for the view used when you have your iPad in landscape mode and you compose a new e-mail. A view popping up from beneath while you can still see the main view in the background.
I've been looking around, but I have no clue what to search for!
Here's an image of something like what I'm talking about, only I would need it to say "Save" instead of "Send" and without the "to/Cc/subject"-fields, and I guess I would require an NSString as return value. Any clues?
Or something similar!
This is called modal presentation style.
You can present any UIViewController or its subclasses.
Set the modalPresentationStyleproperty to UIModalPresentationFormSheetand present this viewController from an parent viewController (your tableViewController perhaps) with the presentViewController:animated:completition: method.
Take a look at the docs.
In Interface Builder, search for an object called "Container View". You can include whatever you want in this container and show/hide it when you need.
Related
I have been using this:
UIApplication.sharedApplication().keyWindow?.rootViewController!.view.addSubview(self.customView)
To add a modal view over all the views in the view hierarchy in app.
But this is giving me problem. It adds subview as expected sometimes but sometimes it doesn't' work.
In what case this wont work and what's the best way to add modal view in view hierarchy like UIAlertView.
Depending on what's happening, there can be more than one UIWindow at a time - for example, if a system alert shows up, you will have two separate windows (one for your view controller, one for the alert itself).
A similar example can be made for the system keyboard. If the keyboard has focus, that will be your keyWindow.
A way of making sure you are adding the subview on top of all windows, could be: UIApplication.sharedApplication().windows.last?.addSubview(yourSubView).
I've also seen people using the application delegate, with: UIApplication.sharedApplication().delegate?.window.
There's a particular control which I'm trying to build properly. I refer to it as an ImageTile. It's basically a little square box, which, when the user taps it, will present the user (via an action sheet in a popover) the option of selecting an image from the library, or taking a photo. Depending on the response, I then either present the UIImagePickerController inside a popover (for selecting an image) or modally (for taking a new picture). Once they take/select the image, I have a modal view which appears and allows them to edit the picture in a few simple ways. When they finish editing, the modal dismisses, and the original ImageTile, rather than being a blank square box, gets filled up with the user's edited image.
The issue is that this ImageTile control is going to be used profusely throughout several different parts of the application, across numerous View Controller hierarchies, and so on... and I really want it to be a basically totally self-contained unit, such that whenever I stick an ImageTile inside a UIView onscreen, all the above functionality is handled by the ImageTile itself.
Initially, I made it a UIViewController subclass (so it could present modals etc), and just added its view as a subview of a "holder" view onscreen. I know this isn't recommended, as the controller isn't part of the VC hierarchy then... and also, I wound up with some really weird behavior regarding things like autorotation, especially when the camera was involved.
What's the "right" way to implement something like this?
I think what you've done by making it a UIViewController subclass is correct. You should just use the methods that UIViewController exposes for adding child view controllers, such as - addChildViewController:.
You will also note that Interface Builder has a Container View object designed specifically for holding a place in the hierarchy for a child View Controller:
Apologies if this seems a straightforward question! I'm using AVFoundation to build a custom camera app that allows the user to draw on the image after it's taken (similar to snapchat).
I have the camera functionality working. Currently, after the shutter button is pressed I add (as a subview) a standard UIImageView to display the photo taken. Seeing as I want there to be custom options at this stage (including drawing on the image), I proceeded to create my own subclass of UIImageView. I am designing this view in Interface Builder (xib file).
Say for instance I have a button on this custom view, that when pressed, simply deletes the image and takes me back to the camera view to take another image. Can I handle the IBActions for this custom view within the ViewController for my camera view? Is this bad practice?
Any guidance on how best to implement this would be really appreciated! Thanks.
I would not suggest putting the button on your custom view.
I would have the UIViewController display the custom view and also give display a button for your action. Most likely the UIViewController will want to display a UIToolBar at the bottom of the screen which will allow for multiple buttons/actions, but that's up to you.
But why do I say this? Compartmentalization. Your custom view has no need or use for the button. It's meaningless to what your doing... displaying the image. Your custom view will also probably be used in many locations, several of which won't want this button displayed. Even if your custom view had the button it wouldn't know what to do if someone tapped it. It would then have to pass that interaction off the view controller which cares about the action and and handle it. Your custom view will mostly likely have public methods allowing other code to give it directions (like clear or undo).
Depending on the say things go, you may decide you want a custom UIViewController which handles interactions on your custom view. Then any other view controllers could just add it in as a containerized view controller and you could have the same functionality with no code duplication at several places in your applications.
I apologize in advance for not being able to efficiently describe my problem statement. But, I shall include a link to an image to better describe what I'm looking for. Basically I have a Viewcontroller with a TableView inside it and I have a toolbar on top with three bar button items on it. Now what, I want is to be able to have a functionality whereby the user taps on any of these buttons and we go to different views. Now, I would like a design where if possible I stay on the same screen and render the information in the tableview below depending on which button has been pressed. Visually, I'm trying to go for an effect where the button that is pressed is shown as being depressed and information is rendered and on pressing a different button a different view is rendered. I'm familiar with attaching different view controllers to all the buttons and then segueing into those viewers. However, I would like to know if there's a way in which I can stay on the same view controller and just use sub views. If there is, how can I do this from storyboards? Again,, I apologize for being verbose, my picture should hopefully be able to tell you what I'm trying to do.
The link to what I'm trying to achieve: http://imgur.com/GM5eH
Well, one basic solution is simply to add these other views in your controller. Now that subview is set to hidden on viewDidLoad:. Then just create an action, and show the subView. You can size that view however you want, and play around with the other view as well.
Now, there might be a better way to do this, but that is how I would do it.
EDIT - Concerning Apple's method on Calender
Now, I have never tried anything like this, so this is all theory.
First, you create three classes. Each with it's own custom view. This view should be the size you need it on the other (Main View). You can set the size to freeform in the Interface Builder.
Once you have that done, you head to your main view. That view will have the three buttons. Set an IBAction for each of those that creates an instance of each view and places it on the screen. (I am not sure how to accomplish this, but I am sure there is a way. Take a look here: Objective-c Adding subViews in my controller
You should dealloc each view after you head to another view as well for memory management.
Okay, I am still learning how to program and things are moving along quite well, but I have a question for the group about something that has been plaguing me:
How do I create a pop view where the background can still be seen? I mean, say my iPad view has 5 buttons on it, and I want a small square to pop up over where that button was, asking the user a question - how would i do that? Can I make a modal view with an invisible background? (I don't want a UIAlert BTW - I know that would solve my problem, but I am trying to learn how to do this with my own view)
Can anyone point me in the right direction?
You say "pop view" which makes me think you're describing a popover. Have you read the iPad Programming Guide, specifically, the section "Creating and Presenting a Popover"? It really is required reading in this case.
Are you showing the popover from a bar button? If so, you'll want to use presentPopoverFromBarButtonItem:permittedArrowDirections:animated:. If not, you'll need to identify a CGRect that represents the button (you can use its bounds), and then use presentPopoverFromRect:inView:permittedArrowDirections:animated:.
You do not want to obscure the button with the popover. When you show the popover using the above methods, the framework will take care of positioning the popover on-screen. Use the UIPopoverArrowDirectionAny for directions whenever possible.
If you actually want to show a modal view, you can create whatever view you want and then display it in such a way that the background is not fully obscured. Just set the modalPresentationStyle of the view controller to something like UIModalPresentationPageSheet.
You should create a custom UIView with the dimensions and content that you want to display. Then, you can place the custom UIView on screen by calling something like:
//where 'self' is the view controller currently visible and 'customView' is
//the view which has the question for the user. Don't forget to set the
//frame property on customView so that it knows the correct place to display.
[self.view addSubview:customView];
Hope this helps. Andrew