Created
November 19, 2013 15:18
-
-
Save matteom/7546897 to your computer and use it in GitHub Desktop.
Leads table view controller populating the table view from a plist file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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