Objective-c – Swapping tableView into another view within UITableViewController

iphoneobjective c

I'm trying to resize the tableview of a UITableViewController so I can also put some other content in the view. So I'm trying to swap the tableview into a new view. The following works, but if I try to reference self.tableview later, it returns null. What am I doing wrong ?

- (void)viewDidLoad {
    [super viewDidLoad];

    UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; 
    self.tableView.frame = CGRectMake(0, 0, 320, 200);
    [view addSubview:self.tableView];
    self.view = view;
}

Yes, I can probably just use a UIViewController and create my tableview there. I was just trying to avoid doing that if I can, and get the freebies of UITableViewController

Best Answer

To get around the issue I just held on to the tableView and overwrote the tableview getter

- (UITableView*)tableView{
    return myTableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    myTableView = [super tableView];
    UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; 
    self.view = view;
    myTableView.frame = CGRectMake(0, 0, 320, 200);
    [view addSubview:myTableView];
    }
Related Topic