This is for iPhone.
I have a button and when it's clicked I want to pop-up another control which covers the whole screen. This screen could have any number of controls. And I can close this screen by clicking on an x in the top right corner or programmatically inside any event on the new screen.
I could probably do this by using a UINavigationController which just brings me to a new screen and has a link back to the previous screen but I would just like to ask if there is another option?
What I am doing is I have a map which shows a users location from a pin. But if the user wants to type in a new location instead of using the pin location then they will click a button, go to a new screen, type in an address and click a "suggested" address from what they type.
Any advice would be appreciated or a link to a code sample would be great
You can't use popover for iPhone, I think that you can use Modal View.
yourButton.TouchUpInside += (object sender, EventArgs e) =>
{
YourController yourController = new YourController();
yourController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
this.PresentViewController(yourController, true, null);
};
And to close you only need to dismiss the modal.
If it's an iPad app you can use UIPopoverController.
// myvc is an instance of the view controller you want to display in the popup
UIPopoverController pop = new UIPopoverController(myvc);
// target is another view that the popover will be "anchored" to
pop.PresentFromRect(target.Bounds, target, UIPopoverArrowDirection.Any, true);
If it's an iPhone app you can't use UIPopoverController. If you just want a small input box with a single button, you can use UIAlertView (this works for iPhone and iPad)
UIAlertView alert = new UIAlertView();
alert.Title = "Title";
alert.AddButton("OK");
alert.Message = "Please Enter a Value.";
alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
alert.Clicked += (object s, UIButtonEventArgs ev) => {
// handle click event here
// user input will be in alert.GetTextField(0).Text;
};
alert.Show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With