UIPopoverController例子

       UIPopoverController做了个例子,在做时碰到一个郁闷的问题。例子代码检查没有问题,也不报错,可popover就是不显示,纠结哈。参考了些博文也没找到答案,最后无意中发现popover显示的位置我设的是向下UIPopoverArrowDirectionDown导致没能显示出来。

以下为实例:

//
//  SearchPopoverViewController.h
//  Ipad004
//  搜索框-显示popover
//  Created by Dwen on 12-11-2.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SearchPopoverViewController : UITableViewController
@end

 

#import "SearchPopoverViewController.h"

@interface SearchPopoverViewController ()

@end

@implementation SearchPopoverViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return YES;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }
    cell.textLabel.text = @"商品";
    cell.detailTextLabel.text = @"约800条";
    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 
}

@end
 
SearchPopoverViewController *spVC = [[SearchPopoverViewController alloc] initWithNibName:@"SearchPopoverViewController" bundle:nil];

//    SearchPopoverViewController *spVC = [[SearchPopoverViewController alloc] initWithStyle:UITableViewStylePlain];
    spVC.contentSizeForViewInPopover = CGSizeMake(200, 300);
    popover = [[UIPopoverController alloc] initWithContentViewController:spVC];
    [popover presentPopoverFromRect:[self.searchBar bounds] inView:self.searchBar permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

 


 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值