我正在尝试使用包含plist值的数组填充表视图。一切看起来都正确,但是当我编译它时,它并没有显示任何表格。关于为什么的任何线索?
#import "Person.h"
@implementation Person
-(void) setAge:(int)age{
_age = age;
}
-(int) age {
return _age;
}
-(void) setName:(NSString *)name{
_name = name;
}
-(NSString *) name{
return _name;
}
-(void) setJob:(NSString *)job{
_job = job;
}
-(NSString *) job{
return _job;
}
@interface Person : NSObject {
int _age;
NSString * _name;
NSString * _job;
}
-(void) setAge: (int) age;
-(int) age;
-(void) setName: (NSString *) name;
-(NSString *) name;
-(void) setJob: (NSString *) job;
-(NSString *) job;
-(NSString *) summaryString;
@end
#import <UIKit/UIKit.h>
@interface PeopleListViewController : UITableViewController
//Array to hold list of people
@property(nonatomic, strong) NSArray *people;
@end
#import "PeopleListViewController.h"
#import "Person.h"
@interface PeopleListViewController ()
@end
@implementation PeopleListViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *peopleArray = [NSMutableArray array];
NSArray *array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"people" ofType:@"plist"]];
for(NSDictionary *dict in array){
Person *person = [[Person alloc] init];
person.job = [dict objectForKey:@"name"];
person.age = [[dict objectForKey:@"age"] intValue];
person.job = [dict objectForKey:@"job"];
[peopleArray addObject:person];
}
self.people = peopleArray;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return 15;
}
- (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];
}
cell.textLabel.text =
[[self.people objectAtIndex:indexPath.row] objectForKey:@"name"];
return cell;
}