MonoTouch for iPad: how to show popup dialog?

I just started learning application development (primarily) for the iPad using MonoTouch. Perhaps due to my many years of experience in the C # world, this makes my switch very complicated, and sometimes I feel dumb. It is very simple in C #, but it makes me scratch my head ...

Popup dialog box?

For iPhone, you rarely have this requirement, because everything that you show will occupy the entire screen, so you just create a controller for each popup.

I have much more space for the iPad, and I don’t want the whole screen to be occupied by several controls (like the login screen). So I want to show this as a popup. I have seen this in other iPad apps.

From what I learned, I need to use a UIAlertView or UIActionSheet for this. But I don’t understand that, as all the examples I read show, you need to create all the controls from the code.

What I would like to do is create a user interface using IB and connect it to the UIActionSheet. Is it possible? How to do it?

+4
source share
3 answers

If this is an iPad app, you need to use the UIPopoverController. This is a pop-up “window” that contains a view and is associated with an area on the screen, such as a button on a toolbar or a rectangle (for example, a UIButton frame).

To use this, create a new instance of the UIPopoverController using the constructor that takes the UIViewController and pass in the view you want to show.

Due to garbage collection considerations, make sure you store the UIPopoverController in the class property.

You might also want to clear this property when the popover is closed. To support this, we subclassed the UIPopoverController, added an event that could be hooked up by the caller, then redefined the Dismiss method and fired the associated event, if any, in the redefined method.

Once you create a popover instance, you will want to show it. You can do this using one of the PresentFromxxx methods. If you represent this using a button (not a toolbar), you can call PresentFromRect using the button frame as a rectangle.

The presented view can control its size by setting the ContentSizeForViewInPopover property in the ViewDidLoad method.

+6
source

You cannot edit a UIActionSheet or UIAlertView from the Builder interface.

What you can do is create a view in Interface Builder and display it on top of your other views, but it looks like you don't want to occupy the entire screen, and that is what will happen. The following is an example of a modal view controller: http://pastebin.com/h221BQdK

I think you should just follow the examples you provided and create a UIAlertView from the code, perhaps put it as a static class. I created a MessageBox class that looks more like windows, but you can also place text boxes for login. Look at the application store login window, this is a worthy example of how it will look.

+1
source

Create a view manager called extraviewcontroller, set its height width to 300 * 215. and write the code below

inviewdidload

pickerviewTitle = [[UIPickerView alloc] initWithFrame:CGRectMake(0,0, 383, 250)]; pickerviewTitle.delegate = self; pickerviewTitle.tag = 0; pickerviewTitle.showsSelectionIndicator = YES; controller = [self.storyboard instantiateViewControllerWithIdentifier:@"ExtraViewController"]; popovercontroller = [[UIPopoverController alloc] initWithContentViewController:controller]; popovercontroller.delegate = self; 

then

 UIActionSheet *actionSheet1 = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Done" destructiveButtonTitle:nil otherButtonTitles:nil]; actionSheet1.tag = 0; actionSheet1.actionSheetStyle = UIActionSheetStyleDefault; [actionSheet1 addSubview:pickerviewTitle]; [actionSheet1 setFrame:CGRectMake(0, 0, 600, 400)]; [controller.view addSubview:actionSheet1]; if ([popovercontroller isPopoverVisible]) { [popovercontroller dismissPopoverAnimated:YES]; } else { //the rectangle here is the frame of the object that presents the popover, //in this case, the UIButton… CGRect convertedFrame = yourclickbutton.frame; [popovercontroller presentPopoverFromRect:convertedFrame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES]; } 
0
source

All Articles