Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swapping tableView into another view within UITableViewController

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

like image 503
dizy Avatar asked Sep 26 '26 00:09

dizy


1 Answers

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];
    }
like image 80
dizy Avatar answered Sep 28 '26 15:09

dizy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!