MrJonesIsMe
MrJonesIsMe

Reputation: 39

UITableView data displays in simulator, but not on actual device

I have created a custom tableViewCell and am populating it with data. The data appears fine in the simulator but does not populate on the device. Below is my code. Thanks for any help in advance this one is really catching me.

viewDidLoad:

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self initColors];
[self initDB];
[self.pointsTableView reloadData ];
}

numberOfSections/RowsInSection:

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[self.dealNameCountDict allKeys]count];
}

cellForRowAtIndexPath:

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

if (cell == nil)
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ProfileTableViewCell" owner:self options:nil];
    cell = [nib objectAtIndex:0];
}

// Configure the cell...
NSArray<NSString*> *keys = [self.dealNameCountDict allKeys];
NSString *k = [keys objectAtIndex:indexPath.row];

// should be a dictionary for businessNameLabel
cell.textLabel.text = k;
cell.detailTextLabel.text = [[self.dealNameCountDict objectForKey:k] stringValue];


return cell;
}

Upvotes: 1

Views: 193

Answers (2)

MrJonesIsMe
MrJonesIsMe

Reputation: 39

Turns out there was another file local function which initialized dealNameCountDict after the table had been created and after viewDidLoad was called. I just added

[self.pointsTableView reloadData ];

to the end of that function and this seems to have solved the async issues.

Upvotes: 0

Maurice
Maurice

Reputation: 1464

You are probably populating your dictionary after reloading the table view. The device runs usually a little faster than the simulator - so if you get the data asynchonously, that may be the reason.

Try reloading the table view in the setter of your dictionary.

- (void)setMyDictionary:(NSDictionary*)myDictionary {

   _myDictionary = myDictionary;
   [table reloadData];

}

Upvotes: 1

Related Questions