I’ve pieced together a few snippets from around stackoverflow, but I can’t seem to get this behaving as I’d expect.
I am trying to take the NSUSerDefaults and populate a UITableView with the data.
The dictionary is populated, and all the NSLog’s output what I expect. But the final cellForRowAtIndexPath is not returning anything to the table view.
I have the cell identifier and reuse set to “cell” but the table view is coming up empty
- (void)viewDidLoad {
[super viewDidLoad];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
myDictionary = [defaults dictionaryRepresentation]; }
NSLog(@"Dict: %@",myDictionary);
NSLog(@"count: %d", [myDictionary count]);
NSArray * allKeys = [myDictionary allKeys];
NSLog(@"%@",allKeys);
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1; }
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [myDictionary count]; }
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSArray * allKeys = [myDictionary allKeys];
cell.textLabel.text = [myDictionary objectForKey:[allKeys objectAtIndex:indexPath.row]];
cell.detailTextLabel.text = [myDictionary objectForKey:[allKeys objectAtIndex:indexPath.row]];;
return cell; }
at the head of my myTableViewController.m file I have:
@interface myTableViewController ()
{
NSDictionary *myDictionary;
}
Summary from the comments.
Update your .m as follows (typed quickly – possible typos below):