I have set the delegate and datasource to the File's Owner, the outlet is set properly in the xib file. Now for the .h file:
@interface ProductsViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>{
IBOutlet UITableView *objTableView;
}
@property(nonatomic,strong)IBOutlet UITableView *objTableView;
In the .m file:
NSLog(@"%@",self.objTableView);
[self.objTableView reloadData];
For the first time, self.objTableView is set properly:
NSLog(@"%@",self.objTableView);
gives:
<UITableView: 0x1d9a5800; frame = (4 54; 532 660); clipsToBounds = YES; autoresize = W+H;
But for next time I got a (null) table view object and so the reloadData doesn't refresh the table view. How to fix that, thanx in advance.
EDIT:
I am using the Afnetworking method JSONRequestOperationWithRequest like the following:
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){
[SVProgressHUD dismiss];
//Get the response from the server
//And then refresh the tableview
[self.objTableView reloadData];//I shouldn't put this here, it should be in the main thread
}failure:^(NSURLRequest *request, NSHTTPURLResponse *response,NSError *error, id JSON){
[SVProgressHUD dismiss];
//Alert the error message
}];
[operation start];
[SVProgressHUD showWithStatus:@"Searching for products, please wait.."];
Actually, JSONRequestOperationWithRequestrun asynchronous and so not in the main thread, however it turned that the UI updates should be done in the main thread, so I need to remove [self.objTableView reloadData]; outside that method. But where? how to make sure to run it in the main thread after JSONRequestOperationWithRequest will finish?