Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableViewController's view added as subview to UIViewController crashes app
    primarykey
    data
    text
    <p>I have these two classes in my project:</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "TableViewController.h" @interface MainViewController : UIViewController @end </code></pre> <p>and</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface TableViewController : UITableViewController @end </code></pre> <p>Within MainViewController.m, I am trying to do this:</p> <pre><code>TableViewController *tview = [[TableViewController alloc] initWithNibName:@"TableViewController" bundle:nil]; tview.tableView.dataSource = tview; tview.tableView.delegate = tview; [self.view addSubview: tview.view]; </code></pre> <p>However, this is crashing with an:</p> <pre><code>-[MainViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xb52dc90' </code></pre> <p>I don't understand why MainViewController is becoming the datasource/delegate for the TableViewController, when I already set the delegate/datasource in the init above. I also tried to set TableViewController's delegate/datasource to self from within its viewDidLoad, but the MainViewController still keeps acting as the delegate/datasource, regardless. I tried with the nib files hooked up and not hooked up, but no difference.</p> <p>Ideally, I want the TableViewController to act as the delegate and datasource, and have its view added to MainViewController. How can I get this done?</p> <p>Thank you!</p> <p>Note: Neither solution worked for some reason. In the end, I recreated TableViewController as inheriting from UIViewController and set it as and things went normally then.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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