gpt4 book ai didi

ios - PopOver ViewController 屏幕尺寸不一致

转载 作者:行者123 更新时间:2023-11-29 02:26:12 25 4
gpt4 key购买 nike

我创建了一个弹出 View Controller ,大小为 300*250,但是一旦我单击弹出按钮,它会显示比我定义的更大的 View 。

#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

最佳答案

模拟尺寸并没有定义view controller的尺寸,它只是用来在storyboard中显示那个尺寸的view controller。

要更改在 View 中使用这个的大小将出现在 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 重复

关于ios - PopOver ViewController 屏幕尺寸不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27509063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com