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];

 


UIPopoverController例子

 

 

 

你可能感兴趣的:(apple,cocoa,Objective-C)