2011-10-12 30 views
0

我想创建一个简单的参考应用程序,列出一组人,他们的工作头衔和他们的肖像。到目前为止,我所拥有的是人员名单和他们的职位。它工作正常,但我认为我应该做得不同。在PList中访问字典for UITableView

从阅读其他职位,我想我应该使用字典。这是我的plist目前的样子:

my plist

这是怎么我的代码看起来的重要位:

@implementation RootViewController 

@synthesize staffArray, subtitleArray; 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    NSString* path = [[NSBundle mainBundle] pathForResource:@"StaffData" ofType:@"plist"]; 
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; 
    NSMutableArray *tmpNameArray = [dict objectForKey:@"Root"]; 
    self.staffArray = [[NSMutableArray alloc] initWithArray:tmpNameArray copyItems:YES]; 
    NSMutableArray* tmpSubtitleArray = [dict objectForKey:@"Subs"]; 
    self.subtitleArray = [[NSMutableArray alloc] initWithArray:tmpSubtitleArray copyItems:YES]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [staffArray count]; 
} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Configure the cell. 
cell.textLabel.text = [staffArray objectAtIndex:indexPath.row]; 
cell.detailTextLabel.text = [subtitleArray objectAtIndex:indexPath.row]; 
return cell; 
} 

使用两个数组类型的失败OOP的目的,我认为,因为在这种情况下,人们与职位无关;他们恰好是在相同的顺序。我想创建例如:

数组称为乔纳斯,第一个值=工作职位,第二个值= pathToImage.png。

另一个阵列叫安德烈亚斯,等等等等等等

我该怎么办?

回答

0

我认为,作为一个开始,您的设计缺少一个“员工”对象,它具有像“名称”,“JobTitle”等数据成员......在您完成此设置后,只需创建一组人员并通过索引从那里采取任何你需要的。