iOS Development UI Chapter-popovercontroller Brief Introduction

Source: Internet
Author: User

First, Brief introduction

1. What is Uipopovercontroller

is a common controller in ipad development (not allowed on iphone)

Unlike other controllers, it inherits directly from NSObject and does not inherit from Uiviewcontroller

It takes up only a portion of the screen space to present information and is displayed at the front of the screen

2. Steps to use

To display a uipopovercontroller, you need to go through the following steps

(1) Setting up the content controller

  since Uipopovercontroller directly inherits from NSObject, it does not have the ability to visualize. So the uipopovercontroller above must be provided by another controller that inherits from the Uiviewcontroller , which is called the "content controller".

(2) Setting the size of the content

Show how much screen space it occupies

(3) show where it pops up

Ii. Specific steps

code example:

To create a new ipad project, write the following code:

Create a new controller that inherits from UITableView, making it a content controller for Popovercontroller.

YYMENUVIEWCONTROLLER.M file

1 //2 //YYMENUVIEWCONTROLLER.M3 //01-popovercontroller Brief Introduction4 //5 //Created by Apple on 14-8-17.6 //Copyright (c) 2014 Yangyong. All rights reserved.7 //8 9 #import "YYMenuViewController.h"Ten  One @interfaceYymenuviewcontroller () A@property (nonatomic,strong) Nsarray *menus; - @end -  the @implementationYymenuviewcontroller -  --(Nsarray *) Menus - { +     if(_menus==Nil) { -[Email protected] [@"Listing 1",@"Listing 2",@"Listing 3",@"Listing 4"]; +     } A  return_menus; at } -- (void) Viewdidload - { - [Super Viewdidload]; - } -  in-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView - { to     return 1; + } --(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section the { *     returnSelf.menus.count; $ }Panax Notoginseng-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath - { the     StaticNSString *id=@"ID"; +UITableViewCell *cell=[TableView Dequeuereusablecellwithidentifier:id]; A     if(cell==Nil) { theCell=[[UITableViewCell Alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:id]; +     } -      $cell.textlabel.text=Self.menus[indexpath.row]; $     returncell; - } -  the @end

YYVIEWCONTROLLER.M file

1 //2 //YYVIEWCONTROLLER.M3 //01-popovercontroller Brief Introduction4 //5 //Created by Apple on 14-8-17.6 //Copyright (c) 2014 Yangyong. All rights reserved.7 //8 9 #import "YYViewController.h"Ten #import "YYMenuViewController.h" One  A @interfaceYyviewcontroller () - @property (Nonatomic,strong) Uipopovercontroller *popover; - @end the  - @implementationYyviewcontroller -  -- (void) Viewdidload + { - [Super Viewdidload]; + } A  at-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event - { -     //1. Create a new content controller -Yymenuviewcontroller *menuvc=[[Yymenuviewcontroller alloc]init]; -      -     //2. Create a new Popovercontroller and set its content controller inSelf.popover=[[Uipopovercontroller ALLOC]INITWITHCONTENTVIEWCONTROLLER:MENUVC]; -      to     //3. Setting the size +Self.popover.popovercontentsize=cgsizemake ( -, $); -      the     //4. Display * [Self.popover PresentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem permittedarrowdirections : Uipopoverarrowdirectionany Animated:yes]; $ }Panax Notoginseng @end

Implementation results such as:
  

Description: Added a navigation controller to the storyboard and added two buttons.

  

Three, common error

This error is often encountered during the use of PopOver.

-[uipopovercontroller Dealloc] Reached while popover is still visible.

The general meaning of the error is thatPopOver is destroyed when it is still visible (called Dealloc)

A conclusion that can be drawn from a mistake

When PopOver is still visible, popover objects are not allowed to be destroyed.

Before destroying PopOver objects, be sure to let popover disappear (not visible)

For example: In the above code, if the global variable popover is not applicable, then the above error will occur.

iOS Development UI Chapter-popovercontroller Brief Introduction

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.