Ios-uipopovercontroller (ipad)

Source: Internet
Author: User
Tags uikit

Uipopovercontroller can only be used on ipad devices; The function is to display temporary content, which is always displayed at the front of the current view, with an arrow that indicates which button is bouncing from, and disappears automatically when you click elsewhere in the interface.     (1) Create two Uiviewcontroller classes (Listviewcontroller and Oneviewcontroller)   Listviewcontroller as a pop-up controller view display    (2) Build a pop-up view to show what it is that pops up a table.   [objc]  #import <UIKit/UIKit.h>     @interface Listviewcontroller: Uiviewcontroller <UITableViewDelegate,UITableViewDataSource>       @property ( strong,nonatomic) UITableView *favoritetableview;//Favorites Table View     @property (strong,nonatomic) Nsmutablearray *list;//Favorites list     @end &NBSP;&NBSP;[OBJC]   #import "ListViewController.h"   #import "ThreeViewController.h"   @interface Listviewcontroller ()     @end    @ Implementation Listviewcontroller    -(ID) initwithnibname: (NSString *) Nibnameornil bundle: (NSBundle *) Nibbundleornil  {     self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil];  & nbsp   if (self) {        // Custom initialization     }      return self;      -(void) viewdidload  {     [Super Viewdidload];            self.list = [[Nsmutablearray alloc] initwithobjects:@ "Willingseal", @ "http://blog.csdn.net/ Willingseal?viewmode=contents ", @" some things are not because of the hope to adhere to, but adhere to see the hope, "@" Love はひとりの cheat Master occupies をしていた horse deer な fairy tale ... バカ Love はひとりの scams bully teacher occupies love をしていた deer な children ", nil nil";              [self addtableview];        }    -(void) didreceivememorywarning  {     [Super Didreceivememorywarning];     /Dispose of any resources, can be recreated.  }    //Initialize table view  -(void) Addtableview {           Self.favoritetableview = [[UITableView alloc]initwithframe:cgrectmake (0, 0, 400,500) style:uitableviewstyleplain];// Initialize Tabview     //&NBSp  self.favoritetableview.center =cgpointmake (self.view.center.x, self.view.center.y-70); Central location of//tableview      self.favoriteTableView.delegate = self;      self.favoritetableview.datasource=self;      Self.favoritetableview.scrollenabled=yes;//tabview Slide     //    self.favoritetableview.layer.cornerradius=15;//fillet size           //   _ Logintableview = TableView;      Self.favoriteTableView.backgroundColor = [Uicolor colorwithpatternimage:[uiimage imagenamed:@] Bg.png "];      [Self.view AddSubview:self.favoriteTableView];              }         #pragma mark- Table View data source    //line height  -(cgfloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath  {     return;  }    //Number of section  -(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView  {     return 1;        }    //section how many lines  -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) sectionindex  {     NSLog (@ "list is:%lu", [self.list Count]);            return [self.list count];;  }    //cell content  -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath  {     static NSString *cellidentifier = @ "Cell"; nbsp;    UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier];            if (cell ==nil) {         cell = [[UITableViewCell Alloc]initwithstyle:uitableviewcellstyledefault Reuseidentifier:cellidentifier];          Cell.selectionstyle = Uitableviewcellselectionstylenone;                              &NBSP;&N bsp;   }      Nsinteger row = [Indexpath row];      Cell.textLabel.text = [Self.list objectatindex:row];                        return cell;      //Click on a table view cell  -(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{         NSString * Selectstr =[[ NSString Alloc] initwithformat:@ "%@", [Self.list ObjectAtIndex:indexPath.row]];      NSLog (@ "%@", [Self.list ObjectAtIndex:indexPath.row]);          Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Willingseal" Message:selectstr delegate:self cancelbuttontitle:@ "OK" otherbuttontitles:nil nil];     [Alert show]; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP,}         @end    (3) Click button, pop-up table &NBSP;[OBJC]   #import <UIKit/UIKit.h>   #import "ListViewController.h"  @ Interface Oneviewcontroller:uiviewcontroller <uipopovercontrollerdelegate>{       & nbsp   Uipopovercontroller *popovercontroller;  }    -(Ibaction) Tap: (UIButton *) sender;     @end &NBSP;&NBSP;[OBJC]  -(ibaction) Tap: (UIButton *) Sender {       & nbsp   Listviewcontroller *LISTVC =[[listviewcontroller alloc] init];//initialize Listviewcontroller      Popovercontroller = [[Uipopovercontroller alloc] initwithcontentviewcontroller:listvc];// Initialize Popovercontroller-uipopovercontroller the contents of the controller must be provided by a controller Viewcontroller                  [Popovercontroller setpopovercontentsize:cgsizemake (400, 500)];//set Popovercontroller content size      [Popovercontroller setdelegate:self];// Set Popovercontroller agent            [Popovercontroller presentpopoverfromrect: Sender.frame InView:self.view Permittedarrowdirections:uipopoverarrowdirectionany animated:yes];// -the third parameter permittedarrowdirections is to set the direction of the arrow, you can pop up/down/left/right in different directions-popup window with arrows, this method is used on the View pop-up window, Another use in the navigation Bar (Uibarbuttonitem) pop-up Window-(void) Presentpopoverfrombarbuttonitem: (Uibarbuttonitem *) Item Permittedarrowdirections: (uipopoverarrowdirection) arrowdirections animated: (BOOL) animated;                    }     #pragma mark- Popovercontroller  -(BOOL) Popovercontrollershoulddismisspopover: (Uipopovercontroller *) PopoverController  {     return YES;  }    //Let it disappear  -(void) Popovercontrollerdiddismisspopover: (Uipopovercontroller *) Popovercontroller  {     NSLoG (@ "closed popvercontroller");        }  

Ios-uipopovercontroller (ipad)

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.