zoukankan      html  css  js  c++  java
  • UIPopoverController的使用

    对UIPopoverController的使用(2011-06-20 18:07:21)效果如下:
    对UIPopoverController的使用



    实现如下:
    首先加入委托:UIPopoverControllerDelegate
    先创建一个popover和实例化tableview的类(该类的xib文件中,view中就放了一个tablview):
    UIPopoverController *popover;
    popTableViewController *popoverContent;

    在CustomerDetailVC.m放入:
    #import "CustomerDetailVC.h"
    #import "popTableViewController.h"
    @implementation CustomerDetailVC
    //点击Country后面按钮的时候,弹出popover:
    -(IBAction)btnPressed:(id)sender
    {
    popoverContent.oceanaViewController = self;
       
       popover =[[UIPopoverController alloc]initWithContentViewController:popoverContent];
       [popoversetPopoverContentSize:CGSizeMake(330,330)];
       popoverContent.contentSizeForViewInPopover=popoverContent.view.bounds.size;
       popoverContent.popoverController = popover;
       [popoverpresentPopoverFromRect:((UIView *)sender).frame
                          inView:self.view
            permittedArrowDirections:UIPopoverArrowDirectionAny
                        animated:YES];
       [popoverContentrelease];     //在这里popoverContent的retainCount =4;
       [popoverContent.myArray release];
    }
    -(void)popoverControllerDidDismissPopover:(UIPopoverController*)popoverController{
       if (popover){
          [popoverdismissPopoverAnimated:YES];
          [popoverrelease];
          popover=nil;
          if(popoverContent != nil) {
             [popoverContent release];
             popoverContent = nil;
          }
       }
    }
    //closing popover
    -(void)killPopoversOnSight {
       if (popover){
          [popoverdismissPopoverAnimated:NO];
       }
    }
    在popTableViewController.h文件中:
    #import "CustomerDetailVC.h"
    @class CustomerDetailVC;
    @interface popTableViewController :UIViewController<UITableViewDelegate,UITableViewDataSource>{
       IBOutletUITableView *myTableView;
       NSMutableArray *myArray;
       UIPopoverController   *popoverController;
       CustomerDetailVC *oceanaViewController;
       NSString*selectStr;
       
    }

    @property (nonatomic,retain) UITableView *myTableView;
    @property (nonatomic,retain) NSMutableArray *myArray;
    @property (nonatomic,retain) UIPopoverController*popoverController;
    @property (nonatomic,retain) NSString *selectStr;
    @property (nonatomic,assign) CustomerDetailVC*oceanaViewController;
    实现文件中:
    #import "popTableViewController.h"
    @implementation popTableViewController
    @synthesize myTableView;
    @synthesize selectStr;
    @synthesize myArray;
    @synthesize popoverController;
    @synthesize oceanaViewController;


    -(void)viewDidLoad
    {
       [myTableViewsetDelegate:self];
       [myTableViewsetDataSource:self];
    }
    - (NSString *)tableView:(UITableView *)tableViewtitleForHeaderInSection:(NSInteger)section{
       return@"Name";
    }
    //指定有多少个分区(Section),默认为1
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
       return1;
    }

    //指定每个分区中有多少行,默认为1
    - (NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section{
       return[myArray count];
    }
    //绘制Cell
    -(UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath {
       
       staticNSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
       UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:SimpleTableIdentifier];
       if (cell ==nil) {
           cell = [[[UITableViewCell alloc] initWithFrame:CGRectZeroreuseIdentifier:SimpleTableIdentifier] autorelease];
       }
       cell.textLabel.text =[myArray objectAtIndex:indexPath.row];
       returncell;
    }
    - (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath {
       selectStr=[[NSString alloc] initWithFormat:@"%@",[myArrayobjectAtIndex:indexPath.row]];
       [oceanaViewController killPopoversOnSight];
       [oceanaViewController textGetValue:selectStr];//CustomerDetailVC中的一个方法
       [selectStrrelease];
    }
  • 相关阅读:
    SharePoint 2010 编程链接两个web part
    SharePoint 2010 Value does not fall within the expected range
    SharePoint 自定义开发chart web part
    跨站点显示SharePoint 列表或者文档库 cross site
    SharePoint Javascript 改变当前站点语言
    【转】 C++11中值得关注的几大变化
    XPM
    Thinking in C++ 第一章 对象导言
    Thinking in C++ 第4,5,6,7章
    Internal DSL
  • 原文地址:https://www.cnblogs.com/a7345678/p/2572453.html
Copyright © 2011-2022 走看看