Hello, I'm creating a tableView programatically without IB, and I cannot seem to figure out why my plist data isn't being displayed in the table.
My .h file:
and my .m file:
My plist looks like this:
Ideally, this is the end result I'm looking for, where each Row has 3 cells that show the Name, Email, and Phone keys.
Thank you in advance for any help you can provide.
My .h file:
Code:
#import <UIKit/UIKit.h>
@interface List : UIViewController <UITableViewDelegate,UITableViewDataSource>
{
NSDictionary *data;
NSArray *tableDataSource;
}
- (IBAction)Done:(id)sender;
@property (nonatomic, retain) NSDictionary *data;
@property (nonatomic, retain) NSArray *tableDataSource;
@end
and my .m file:
Code:
#import "List.h"
#import "ViewController.h"
@interface List ()
@end
@implementation List
@synthesize tableDataSource, data;
- (void)viewWillAppear:(BOOL)animated
{
UITableView *_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, 1024, 704)];
[self.view addSubview:_tableView];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"Data.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:filePath];
self.data = tempDict;
self.tableDataSource = [tempDict objectForKey:@"Rows"];
[_tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)_tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.tableDataSource count];
}
- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.textLabel.text = [tableDataSource objectAtIndex:indexPath.row];
return cell;
}
- (IBAction)Done:(id)sender {
ViewController *mainView = [[ViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:mainView animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
@end
My plist looks like this:

Ideally, this is the end result I'm looking for, where each Row has 3 cells that show the Name, Email, and Phone keys.

Thank you in advance for any help you can provide.
Last edited: