0
votes

My code creates a basic UITableView base class programmatically.

@interface BaseTableViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
UITableView *tableView;
UITableViewStyle tableViewStyle;

}

The loadView method sets basic properties of the tableView

- (void)loadView
{
[super loadView];
tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 338) style:tableViewStyle];
tableView.dataSource = self;
tableView.delegate = self;

UINavigationBar *navBar = self.navigationController.navigationBar;
navBar.barStyle = [UIUtils barStyle];
navBar.tintColor = [UIUtils tintColor];

if (tableViewStyle == UITableViewStyleGrouped) tableView.backgroundColor = [UIUtils tableBGColor];

[self.view addSubview:tableView];

}

I then subclass this base class since I want to add specific content to the table. The content is displayed and I am able to scroll the tableview to see all the content in the view. Afterward I decide to increase the tableView height by 35. In the subclass I override the loadView method and add

- (void)loadView
{
[super loadView];
self.tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height + 35);
}

After adjusting the tableView frame height I cant scroll the required amount to see all of the table content any more. If I tap the table and drag it the content will come into view but when I release it the content snaps back out of the view and out of sight. I looked at several other posts and the solution seems to be increasing the contentSize of the tableView (its UIScrollView base class). I tried it in both loadView and viewDidLoad methods but has not effect.

self.tableView.contentSize = CGSizeMake(self.tableView.contentSize.width, self.tableView.contentSize.height + 35);

I had a problem similar to this before but tableView was in a Xib file. I ended up just manually increasing the height of the scrollview in IB but that is not an option for me now. Any obvious solutions?

Thanks...

1

1 Answers

0
votes

I resolved the issue however am at somewhat of a loss why the following code is the fix? I was increasing tableview size but not view size. Increased both and was then able to scroll over all of the content in the table.

- (void)loadView
{
[super loadView];

// increase the size of the view and tableview by height of the statusbar frame which was removed...
self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height + 35);
self.tableView.frame = CGRectMake(0, 0, self.tableView.frame.size.width, self.tableView.frame.size.height + 35);

}