PopOverViewController ScreenSize不一致

时间:2014-12-16 16:14:47

标签: ios uitableview uipopovercontroller

我创建了一个popover viewcontroller,大小为300 * 250,但是一旦我点击popover按钮,它就会显示比我定义的更大。

#import <UIKit/UIKit.h>

@interface ZDPopViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITableView *zdTableView;
@property (strong, nonatomic) NSArray *tableData;
@property (strong,nonatomic) UIPopoverController * popoverController;


@end

#import "ZDPopViewController.h"

@interface ZDPopViewController ()

@end

@implementation ZDPopViewController
@synthesize zdTableView,tableData,popoverController;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

     tableData=[[NSArray alloc]initWithObjects:@"TWT",@"TVD",@"TVDSS",@"FREQ", nil];

    self.zdTableView.backgroundColor=[UIColor blackColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [tableData count];
}

- (void)viewWillAppear:(BOOL)animated
{
    self.popoverController.popoverContentSize = CGSizeMake(320, 220);
    [super viewWillAppear:animated];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier=@"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    [cell.textLabel setText:[self.tableData objectAtIndex:indexPath.row]];


    // Configure the cell...

    return cell;
}

enter image description here

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

模拟大小不定义视图控制器的大小,它仅用于显示该大小的故事板中的视图控制器。

要更改使用的大小,视图中将显示View Controller-

- (void)viewWillAppear:(BOOL)animated
{
   CGSize size = CGSizeMake(320, 200); // The size of view in popover you want
   self.contentSizeForViewInPopover = size;
   [super viewWillAppear:animated];
}

试试这篇文章iOS 7 -

popoverController.popoverContentSize = CGSizeMake(320, 845);

同时添加 -

[popoverViewController setPreferredContentSize:CGSizeMake(248.0,216.0)]; 

Here

重复