thebiglebowski11 thebiglebowski11 - 7 months ago 41
iOS Question

Loading data into a uitableview in a uiviewcontroller

I am trying to load data from an array which was made by parsing json... I have the json data in the arrays for sure, but the table view methods are not even being called... I have the table view embedded in a regular uiviewcontroller, it compiles and everything the table just loads no data.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
return 1;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
return [transactions count];

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"any cell"];

if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"any cell"] autorelease];

NSLog(@"got here");
cell.textLabel.text = [names objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [prices objectAtIndex:indexPath.row];
return cell;

- (void)viewDidLoad
[super viewDidLoad];
names = [[NSMutableArray alloc] init];
prices = [[NSMutableArray alloc] init];
[self requestTransactionData];

And here's my .h file...

@interface Controller1 : UIViewController
<UITableViewDelegate, UITableViewDataSource>
UIActivityIndicatorView *loadingIndicator;

IBOutlet UITableView *myTableView;
IBOutlet UILabel *totalLabel;

NSMutableArray *names;
NSArray *transactions;
NSMutableArray *prices;

@property(nonatomic, retain) IBOutlet UIActivityIndicatorView *loadingIndicator;
@property(nonatomic, retain) IBOutlet UILabel *totalLabel;

@property(nonatomic, retain) UITableView *myTableView;

I can't use ARC for this project. I also have it hooked up properly in the interface builder... These seems rather easy but for some reason I can't figure it out. Any suggestions?


  1. I don't see how you know the data source methods are not being called. You are not logging all of them. IfnumberOfRowsInSection is called before transactions is populated or is nil, it returns zero and that's the end of that.

  2. Try calling reloadData using delayed performance so that it happens after transactions is populated. The table view doesn't magically know when your data is ready; you have to tell it.