Skip to content

Instantly share code, notes, and snippets.

@matteom
Created November 19, 2013 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matteom/7546897 to your computer and use it in GitHub Desktop.
Save matteom/7546897 to your computer and use it in GitHub Desktop.
Leads table view controller populating the table view from a plist file
@interface PCLeadsViewController ()
@property NSArray *leads;
@end
@implementation PCLeadsViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *leadsInfoPath = [[NSBundle mainBundle] pathForResource:@"Leads" ofType:@"plist"];
NSArray *leadsInfo = [NSArray arrayWithContentsOfFile:leadsInfoPath];
NSMutableArray *leads = [NSMutableArray new];
for (NSDictionary *leadInfo in leadsInfo) {
PCLead *lead = [PCLead new];
lead.name = leadInfo[@"name"];
lead.surname = leadInfo[@"surname"];
lead.company = leadInfo[@"company"];
[leads addObject:lead];
}
self.leads = [NSArray arrayWithArray:leads];
}
#pragma mark -
#pragma mark UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.leads count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"LeadCell";
PCLeadCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.lead = self.leads[indexPath.row];
return cell;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment