Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>With UITableViewControllers <code>self.view == self.tableView</code>. This is a problem in your case because the desired effect you want requires sibling views (two views added to a common superview) but there is no "superview" for self.tableView.</p> <p>You have to create a new UIViewController subclass that has a UITableView and your ad view as two subviews. You will need to handle things like setting the data source and delegate for the table view, as well as deselecting table view cells when the controller appears. This is a little more work and requires some care, but is definitely doable.</p> <p>I've thrown together a quick example below that will get you started:</p> <pre><code>// Header @interface CustomTableViewController : UIViewController &lt;UITableViewDelegate, UITableViewDataSource&gt; - (id)initWithStyle:(UITableViewStyle)tableViewStyle; @property (nonatomic, readwrite, retain) UITableView* tableView; @end // Source @interface CustomTableViewController() @property (nonatomic, readwrite, assign) UITableViewStyle tableViewStyle; @end @implementation CustomTableViewController @synthesize tableView; @synthesize tableViewStyle = _tableViewStyle; - (id)initWithStyle:(UITableViewStyle)tableViewStyle { if ((self = [super initWithNibName:nil bundle:nil])) { _tableViewStyle = tableViewStyle; } return self; } - (void)loadView { [super loadView]; self.tableView = [[UITableView alloc] initWithStyle:self.tableViewStyle]; self.tableView.autoresizingMask = (UIViewAutoresizingMaskFlexibleWidth | UIViewAutoresizingMaskFlexibleHeight); self.tableView.delegate = self; self.tableView.dataSource = self; [self.view addSubview:self.tableView]; // Create your ad view. ... adView.autoresizingMask = (UIViewAutoresizingMaskFlexibleWidth | UIViewAutoresizingMaskFlexibleTopMargin); [self.view addSubview:adView]; [adView sizeToFit]; self.tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - adView.frame.size.height); adView.frame = CGRectMake(0, self.view.bounds.size.height - adView.frame.size.height, self.view.bounds.size.width, adView.frame.size.height); [self.tableView reloadData]; } - (void)viewDidUnload { self.tableView = nil; [super viewDidUnload]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSIndexPath* selectedIndexPath = [self.tableView indexPathForSelectedRow]; if (nil != selectedIndexPath) { [self.tableView deselectRowAtIndexPath:selectedIndexPath animated:animated]; } } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload