我想显示表格单元格样式2中的字典变量数组,这是联系人应用程序用来显示联系人信息的内容。 出于某种原因,单元格样式不显示。UITableView不显示单元格样式2
具有以下设置的数组变量“arrayOfDictionaries_E”。
/// Dictionary 1
NSArray *dataArray = [NSArray arrayWithObjects: @"Host", hostname, nil];
NSArray *keysArray = [NSArray arrayWithObjects: @"Label", @"Data", nil];
NSDictionary *host_dict = [[NSDictionary alloc] initWithObjects: dataArray forKeys: keysArray];
/// Dictionary 2
NSArray *dataArray2 = [NSArray arrayWithObjects: @"IP", hostIP, nil];
NSArray *keysArray2 = [NSArray arrayWithObjects: @"Label", @"Data", nil];
NSDictionary *ip_dict = [[NSDictionary alloc] initWithObjects: dataArray2 forKeys: keysArray2];
// Storage into Array of Dictionaries
NSArray *dictionariesArray = [[NSArray alloc] initWithObjects: host_dict, ip_dict, nil];
我测试过该数组包含2个字典并且都填充了这两个字典。
所以我遇到了问题: 首先,我希望所有单元格都使用CellStyle2。第二,我希望在新的部分中创建每个字典。 (如联系人应用程序,有选择地捆绑项目组在一起)
因此,这里是我的实现文件中的代码。它是一个采用2个UITableView协议的UIViewController。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return [arrayOfDictionaries_E count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
}
NSDictionary * dict = [arrayOfDictionaries_E objectAtIndex:indexPath.row];
cell.textLabel.text = [dict objectForKey:@"label"];
cell.detailTextLabel.text = [dict objectForKey:@"Data"];
return cell;
}
查找the current tableView here的屏幕截图。
在笔尖上,我已经将tableView出口链接到文件的所有者,并且同样为委托人和来源完成。我已将样式更改为分组。 但是,如上图所示,当我运行该程序单元格不显示在指定的适当样式我也不知道如何让每一行显示在不同的部分。 - >我想到了一个Array> Array> Dictionary变量,但是我完全不知道如何实现这一点。
我还是比较新的Objective-c,所以你可能需要用实际的代码实现来解释,以演示如何实现这一点。
在此先感谢您花时间回答此问题。
谢谢jrturton!标签拼写解决了主要问题。经过一些进一步的代码修改后,我了解了indexPath.Section注释。 现在我同意“为什么不只是有一个单一的字典阵列”。但是我打算使用主机,主机名和它们的字段的数据结构。有没有更简单的方法来实现呢?你能以不同的方式提出建议吗? –
我建议你作为一个新问题提出问题,给出你计划存储的数据种类以及你打算如何处理,你会得到很多帮助。 – jrturton