gpt4 book ai didi

ios - 在 UINavigationController 中设置框架 View Controller View

转载 作者:行者123 更新时间:2023-11-29 13:06:38 25 4
gpt4 key购买 nike

我想改框架,VC不行。这是我的代码:

AZControlViewController *vc = [[AZControlViewController alloc] init];
vc.tableView.frame = CGRectMake(0, 195, 320, 500);
self.vcMaster = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];

AZControlViewControlleris 是一个 UITableViewController

谁能帮帮我?

谢谢!

最佳答案

使用断点或 NSLog 查看 vctableView 属性。它应该是 nil。发生这种情况是因为 View Controller 的 View 组件只会在 View Controller 呈现后才被初始化。

要正确更改 tableView 的框架,请在 AZControlViewController.m 中实现上述方法并根据需要更改框架。

-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.tableView.frame = CGRectMake(0, 195, 320, 500);
}

如果您仍然想从外部类设置此框架,请创建一个属性来存储您想要的框架,然后将此框架分配给 tableView 的框架。

AZControlViewController.h 中:

@property (nonatomic, assign) CGRect tableViewFrame;

AZControlViewController.m 中:

-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.tableView.frame = self.tableViewFrame;
}

还有别的地方:

AZControlViewController *vc = [[AZControlViewController alloc] init];
vc.tableViewFrame = CGRectMake(0, 195, 320, 500);

关于ios - 在 UINavigationController 中设置框架 View Controller View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18465133/

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