[英]iOS - How to set width of TableView in TableViewController?
Try this: 尝试这个:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES]
[self.tableView setFrame:CGRectMake(x, y, width, height)];
}
try this 尝试这个
Chanage the frame in viewWillAppear
在viewWillAppear
更改框架
- (void)viewWillAppear:(BOOL)animated
{
self.view.frame = CGRectMake(0, 0, 200, 200);
[super viewWillAppear:animated];
}
or change in 或改变
Called to notify the view controller that its view is about to layout its subviews.When a view's bounds change, the view adjusts the position of its subviews. 调用此方法以通知视图控制器其视图将要布局其子视图。当视图的边界发生变化时,视图将调整其子视图的位置。
So instead of doing it in view will appear,over ride the willLayoutSubviews : 因此,不是在视图中显示它,而是在willLayoutSubviews中运行 :
-(void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
self.view.frame = CGRectMake(0, 0, 200, 200);
}
or efficient way 或有效的方法
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES]
[self.tableView setFrame:CGRectMake(x, y, 200, 200)];
}
swift3 迅捷3
Change the frame in viewWillAppear
更改viewWillAppear
的框架
override func viewWillAppear(_ animated: Bool) {
self.view.frame = CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(200), height: CGFloat(200))
super.viewWillAppear(animated)
}
or change in 或改变
Called to notify the view controller that its view is about to layout its subviews.When a view's bounds change, the view adjusts the position of its subviews. 调用此方法以通知视图控制器其视图将要布局其子视图。当视图的边界发生变化时,视图将调整其子视图的位置。
So instead of doing it in view will appear,over ride the willLayoutSubviews : 因此,不是在视图中显示它,而是在willLayoutSubviews中运行 :
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
self.view.frame = CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(200), height: CGFloat(200))
}
or efficient way 或有效的方法
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
self.tableView.frame = CGRect(x: CGFloat(x), y: CGFloat(y), width: CGFloat(200), height: CGFloat(200))
}
Why do you need to change the width? 为什么需要更改宽度?
class MyTableViewCell: UITableViewCell {
override func layoutSubviews() {
super.layoutSubviews()
self.frame.size.width = 200
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.