Basic use of Popover for iOS ipad Development

Source: Internet
Author: User

Basic use of Popover for iOS ipad Development

 

I:

Ii. Note:

For method [UIPopoverController dealloc] reached while popover is still visible.
When the popover is still displayed, it crashes.
The popover cannot be suspended when it is displayed.
Popover must be suspended when it disappears

Iii. Core code
-(IBAction) popMenu :( id) item {// 0. content: MenuViewController * menu = [[MenuViewController alloc] init]; // 1. create a UIPopover UIPopoverController * popover = [[UIPopoverController alloc] initWithContentViewController: [[UINavigationController alloc] initWithRootViewController: menu]; // 2. set the size // popover. popoverContentSize = CGSizeMake (320, 44*5); // 3. where to display --> point to item [popover presentPopoverFromBarButtonItem: item permittedArrowDirections ctions: UIPopoverArrowDirectionAny animated: YES]; self. popover = popover ;}
Iv. display all code ViewController
# Import ViewController. h # import MenuViewController. h @ interface ViewController ()-(IBAction) popMenu :( id) item; @ property (nonatomic, strong) UIPopoverController * popover; @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad];} //-[UIPopoverController dealloc] reached while popover is still visible. // when the popover is still displayed, it is suspended // it does not allow the popover to be suspended when it is still displayed // the popover must be suspended when it disappears/*** pop-up Popover menu */-(IBAction) popMenu :( id) item {// 0. content: MenuViewController * menu = [[MenuViewController alloc] init]; // 1. create a UIPopover UIPopoverController * popover = [[UIPopoverController alloc] initWithContentViewController: [[UINavigationController alloc] initWithRootViewController: menu]; // 2. set the size // popover. popoverContentSize = CGSizeMake (320, 44*5); // 3. where to display --> point to item [popover presentPopoverFromBarButtonItem: item permittedArrowDirections ctions: UIPopoverArrowDirectionAny animated: YES]; self. popover = popover;} @ end
MenuViewController
# Import MenuViewController. h @ interface MenuViewController () @ property (nonatomic, strong) NSArray * titles; @ end @ implementation MenuViewController-(void) viewDidLoad {[super viewDidLoad]; self. titles = @ [@ set, @ clear cache, @ exit, @ basic info]; self. title = @ menu; self. view. backgroundColor = [UIColor blueColor]; CGFloat w = 320; CGFloat h = self. titles. count * 44; self. preferredContentSize = CGSizeMake (w, h); // self. ContentSizeForViewInPopover = CGSizeMake (w, h) ;}# pragma mark-Table view data source-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {return self. titles. count;}-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {static NSString * ID = @ cell; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentif Ier: ID]; if (! Cell) {cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: ID];} cell. textLabel. text = self. titles [indexPath. row]; return cell;}-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {UIViewController * vc = [[UIViewController alloc] init]; vc. view. backgroundColor = [UIColor redColor]; [self. navigationController pushViewController: vc animated: YES];} @ end

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.