Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在PList中访问UITableView的词典_Ios_Xcode4 - Fatal编程技术网

Ios 在PList中访问UITableView的词典

Ios 在PList中访问UITableView的词典,ios,xcode4,Ios,Xcode4,我想创建一个简单的参考应用程序,列出一组人、他们的职位和他们的肖像。到目前为止,我掌握的是员工名单和他们的职称。它工作正常,但我认为我应该做得不同 通过阅读其他帖子,我想我应该使用字典。这就是我的PList当前的外观: 这就是我代码中的重要部分的外观: @implementation RootViewController @synthesize staffArray, subtitleArray; - (void)viewDidLoad { [super viewDidLoad]

我想创建一个简单的参考应用程序,列出一组人、他们的职位和他们的肖像。到目前为止,我掌握的是员工名单和他们的职称。它工作正常,但我认为我应该做得不同

通过阅读其他帖子,我想我应该使用字典。这就是我的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的目的,因为在这种情况下,人们与他们的职位没有联系;他们只是碰巧在同一个顺序。我想创建一个示例:

名为Jonas的数组,第一个值=职务,第二个值=pathToImage.png

另一个数组称为Andreas等


我该怎么办?

首先,我认为您的设计缺少一个“Employee”对象,该对象包含“Name”、“JobTitle”等数据成员。。。设置好之后,只需创建一个人员数组,然后根据索引从中获取所需的任何内容