Reputation: 829
I have created a table view like this
@interface RootViewController : UITableViewController{
}
Now i want to change the origin & size of the tableview before displaying.
How can i change it ?
Edit :
- (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;
}
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 .
Upvotes: 1
Views: 10278
Reputation: 7792
If your using StoryBoard and if you have constraints set up. The reloadData will reset whatever you set the frame to. Instead, you should be modifying the constraints. You can do this by creating an outlet and then changing the constant. For instance, below I linked the constraint variable to the top constraint and by setting the constant to -60, it moves it up.
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableConstraint;
_tableConstraint.constant = -60.;
Upvotes: 1
Reputation: 6058
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...
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);
}
Upvotes: 6
Reputation: 5977
you may just get the property *tableView * to do this
tableView.frame = xxxxxx;
but i think you just need a UIViewController contains a UITableView
UITableView tableView = [[UITableView alloc] initWithFrame:(**the size you want**)];
[self.view addSubView:tableView];
Upvotes: 3