开发者

iPhone: How to show pop-up windows and dismiss them

In my Universal App I have a long UITableView with custom cells..and for some cells I may need to show some long pop-up explanaiton about that cell when for instance user clicks a "i" label on the cell. In iPad popover view seems excellent choice for this, but don't know how can I implement this on iPhone, what are the possibilities? Also I want to spend as less time as possible when making it work for iPad- popover view. I want to re-use some of the code or logic i use on iPhone

Things came up to my mind;

-Show explaination in alert shild, but the current look and feel of alert shield is ugly can I customize it however I like and show wherever I line on screen and if I开发者_StackOverflow社区 can make it scrollable;

-Or maybe I can make a uitextview to show on top, but then how will I dismiss it, I will need some buttons there..which sounds tricky.

-UIActionsheet with a uitextview on it, is reasonable here?

Also I found this code in S.O but dont know how to use this in my case;

  newView.frame = CGRectMake(60, 140, 200, 200);
  [parentView addSubview:newView];


Have a look at http://iosdevelopertips.com/open-source/ios-open-source-popover-api-for-iphone-wepopover.html. It's a Popover component for iPhone. I think it works best in your case. You can Google "iphone popover" for more options.


We built an open source library for iPad-like popovers on iPhone allowing you to customise the look and feel of the popovers and place any view or controller inside it.

Watch the project on Github and download it at http://www.50pixels.com/blog/labs/open-library-fppopover-ipad-like-popovers-for-iphone/

On dismissing it, see the following instructions:

Know when a new popover is displayed

- (void)presentedNewPopoverController:(FPPopoverController *)newPopoverController 
  shouldDismissVisiblePopover:(FPPopoverController*)visiblePopoverController;

Use this delegate method to know when a new different popover is displayed. If you want to dismiss the old popover, and release it, send the dismiss message inside this method.

- (void)presentedNewPopoverController:(FPPopoverController *)newPopoverController 
  shouldDismissVisiblePopover:(FPPopoverController*)visiblePopoverController
{
    [visiblePopoverController dismissPopoverAnimated:YES];
    [visiblePopoverController autorelease];
}

Know when the popover is dismissed

- (void)popoverControllerDidDismissPopover:(FPPopoverController *)popoverController;

Use this delegate method to know when the popover is dismissed. This could happen when the user taps outside the popover or when a dismiss message is sent by other actions.


Typically if you used a UIPopover on the iPad you use present a Modal view controller on the iPhone.

So if you create a subclass of UIViewController (e.g. called MyViewController), with the necessary subviews such as a UILabel.

MyViewController *infoViewController = [[MyViewController alloc] init];
//pass data to the new view controller, e.g. 
//[infoViewController setInfoText:...];
[self presentModalViewController:infoViewController animated:YES];
[infoViewController release];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜