Is a change to a UITableView? Can I assign another frame?

Is a UITableView mutable? Can I assign another frame?

I am trying to use this line in a UITableViewController, but it does not work (on iPhone):

self.tableView.frame = CGRectMake(0, 0, 300, 200); 

thanks

+4
source share
7 answers

Not in the UITableViewController, because in the UITableViewController, self.view == self.tableView .

Try using the UIViewController while running the UITableViewDataSource and UITableViewDelegate protocols.

+17
source

You cannot resize self.tableview.frame or self.view.frame if you use UITableViewController. But what you can do is

You can set the top margin using:

 UIEdgeInsets inset = UIEdgeInsetsMake(50, 0, 0, 0); self.tableView.contentInset = inset; 

This is not a good practice, just in case you want more space on top, you can use it.

You should not use a UITableViewController, just use a UIViewController and programmatically create a UITableview

+7
source

Yes, the UITableView resizes, but not when using the UITableViewController.

Try adding a UITableView to a regular UIViewController and implement the necessary delegation methods. This way you get much more flexibility in customizing your UITableView.

Read the following two links

http://www.skylarcantu.com/blog/2009/09/24/dont-use-uitableviewcontroller-really/

http://flux88.com/2010/03/is-uitableviewcontroller-useless/

+4
source

To expand on Berk's answer:

  • Create a standard view controller using the Xcode template.
  • Add <UITableViewDelegate, UITableViewDataSource>
  • Add @property IBOutlet UITableView , add a UITableView object in the XIB and link them.
  • Set the delegate and data source to a UITableView for the class.
  • Add the following methods:

// # pragma mark - UITableViewDataSource

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *cellIdentifier = @"ServiceCell"; UITableViewCell *cell = (UITableViewCell*)[self.tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] init]; } return [cell autorelease]; } 

The result is a UITableViewController with a resizable tableView.

+4
source

You can resize the View table inside the UITableViewController in methods like

 - (void)viewWillAppear:(BOOL)animated { [self.tableView setFrame:CGRectMake(x, y, w, h)]; } 

It also works in viewDidAppear ...

0
source

Try the following:

 - (void)viewDidAppear:(BOOL)animated { // Set your tableView frame in UITableViewController [self.tableView setFrame:CGRectMake(0, 320, 320, 480)]; // To remove the black color space up of the table view and in this case I set it as white [[[UIApplication sharedApplication] keyWindow] setBackgroundColor:[UIColor whiteColor]]; } 
0
source

To resize a UITableView when using the UITableViewController, simply override viewWillLayoutSubviews as follows:

 - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; CGRect frame = self.view.superview.bounds; frame.size.width -= 54.0; self.tableView.frame = frame; } 
0
source

All Articles