Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView delegate and datasource in a separate class after parsing
    text
    copied!<p>I need to set my UITableView delegate and datasource from a separate class (data ready after parsing called by a method), but every time my table is emtpy. I'm using ARC and this is simplified code:</p> <pre><code>//HomeViewController.h #import &lt;UIKit/UIKit.h&gt; #import "TableController.h" @interface HomeViewController : UIViewController { IBOutlet UITableView *table; TableController *tableController; } @end </code></pre> <p>and</p> <pre><code>//HomeViewController.m #import "HomeViewController.h" @interface HomeViewController () @end @implementation HomeViewController - (void)viewDidLoad { [super viewDidLoad]; tableController = [[TableController alloc] init]; table.dataSource = tableController.tableSource.dataSource; table.delegate = tableController.tableSource.delegate; [tableController loadTable]; // HERE I CALL LOADTABLE FROM TABLECONTROLLER CLASS TO PARSE DATA AND POPULATE UITABLEVIEW [table reloadData]; } </code></pre> <p>and</p> <pre><code>// TableController.h #import &lt;UIKit/UIKit.h&gt; @interface TableController : NSObject &lt;UITableViewDelegate, UITableViewDataSource&gt; { UITableView *tableSource; // a lot of NSMutableArray to parse my data } - (void)loadTable; @property (nonatomic, strong) UITableView *tableSource; @end </code></pre> <p>and</p> <pre><code>//TableController.m #import "TableController.h" #import "AFNetworking.h" @interface TableController () @end @implementation TableController @synthesize tableSource; - (void)loadTable { NSURL *parseURL = // remote URL to parse Data NSURLRequest *request = [NSURLRequest requestWithURL:parseURL]; AFJSONRequestOperation *parseOperation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { // code to parse Data and NSLog to test operation [tableSource reloadData]; [tableSource setUserInteractionEnabled:YES]; [tableSource scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES]; } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { NSLog(@"%@", [error userInfo]); }]; [parseOperation start]; [tableSource setUserInteractionEnabled:NO]; } </code></pre> <p>and, obviously, still in TableController.m, all the classic UITableView delegate methods:</p> <pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // my code } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // my code } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { // my code } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { // my code } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ // my code } - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { // my code } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // my code } </code></pre> <p>Well, the parse is perfect (I can test it with a NSLog), but my <strong>table</strong> is empty. Can u help me?</p> <p><strong>EDIT:</strong> In my code <code>loadTable</code> parsing method is asynchronous, so table load with right datasource and delegate but BEFORE all data is parsed; in fact IF I SET a fixed numberOfRows and then SCROLL TABLE I can see all the rows populated. But, when I load HomeViewController, *table is still EMPTY.</p>
 

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