views:

465

answers:

1

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

+1  A: 

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];
    }
dizy
I think I'm having the same issue. In my case, I am overriding loadView and putting up an alternative view (w/ a UILabel and UIActivityIndicator) to display while the table's contents is loading. When the loading is done, I try to display the table view and I see that it's NULL. I'm confused.
Travis