I'm trying to show a responseObject
in a TableView
, but nothing shows. I can print out all the responseObject
's values, but nothing shows in the TableView
when running the app. In the .m file I have this in the ViewDidLoad:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",access_token] forHTTPHeaderField:@"Authorization"];
[manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
//NSLog(@"Info: %@", responseObject);
dataArray = [[NSArray alloc]initWithObjects:responseObject, nil];
//[self.tableViewObject reloadData];
self.tableViewObject.dataSource = self;
self.tableViewObject.delegate = self;
NSLog(@"TableView: %@", _tableViewObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
If I uncomment [self.tableViewObject reloadData];
it gives me this error:
libc++abi.dylib: terminating with uncaught exception of type NSException
And my tableView
in the .m file looks like:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [dataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
}
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
return cell;
}
The .h file looks like this:
#import <UIKit/UIKit.h>
@interface MyCardsVC : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
NSArray *dataArray;
}
@property (weak, nonatomic) IBOutlet UITableView *tableViewObject;
@end
I don't know what I'm doing wrong. I should have connected it right...