casillas
casillas

Reputation: 16813

PopOverViewController ScreenSize Inconsistency

I have created a popover viewcontroller and size is 300*250, but once I click on popover button, it shows me a bigger than I define.

#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

Upvotes: 0

Views: 157

Answers (1)

Kakshil Shah
Kakshil Shah

Reputation: 3816

The simulated size does not define the size of the view controller, it is only used to show the view controller in the storyboard of that size.

To change the size of the use this in the view will appear of the 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];
}

Try this post iOS 7 -

popoverController.popoverContentSize = CGSizeMake(320, 845);

Also Add -

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

Repeat from Here

Upvotes: 1

Related Questions