以编程方式更改tableview的大小 [英] Changing the size of tableview programmatically

查看:93
本文介绍了以编程方式更改tableview的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个这样的表格视图

I have created a table view like this

@interface RootViewController : UITableViewController{

}

现在我想改变原点和价值显示前的tableview大小。

Now i want to change the origin & size of the tableview before displaying.

如何更改?

编辑:

- (id) initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithStyle:UITableViewStyleGrouped];
    self.tableView.frame=CGRectMake(50, 210, self.view.frame.size.width, self.view.frame.size.height);
    return self;
}

我现在遇到的问题是我设置了以下代码。现在这个表视图仍然从我的视图控制器(0,0)的顶部位置显示,而不是根据我的x,y位置。但是如果我将样式更改为组或普通,它只会正常发生。

The problem now i am facing is i have set following code .Now the table view still showing from top position of my view controller(0,0) not according to my x,y position.But if i change the style to group or plain it is only happening properly .

推荐答案

看起来你已经创建了一个新的 tableView 而不是试图移动InterfaceBuilder为你创建的现有的一个。但是,由于您尚未将新的 tableView 添加到视图层次结构中,因此无法看到新的,而您尚未删除原始的...

It looks like you have created a new tableView instead of trying to move your existing one which InterfaceBuilder created for you. But since you have not added the new tableView to the view hierarchy you cannot see the new one, and you haven't removed the original one...

相反,只需移动原始的tableView即可。在 rootViewController viewWillAppear:方法中,执行以下操作:

Instead, just move the original tableView. In your rootViewController's viewWillAppear: method, do the following:

-(void)viewWillAppear:(BOOL)animated
{
    self.tableView.frame = CGRectMake(0, 310, self.view.frame.size.width,200);
}

这篇关于以编程方式更改tableview的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆