Ios plist的截面UITable视图
我有一个plist文件,其内容如下(源代码视图): 我想让大家看看这张表格的各个部分。部分标题确实会显示,但没有内容。我从nslog获得以下信息:Ios plist的截面UITable视图,ios,objective-c,uitableview,plist,Ios,Objective C,Uitableview,Plist,我有一个plist文件,其内容如下(源代码视图): 我想让大家看看这张表格的各个部分。部分标题确实会显示,但没有内容。我从nslog获得以下信息: ( { Rows = ( { name = "Chunky Chips"; price = "25,-"; }, {
(
{
Rows = (
{
name = "Chunky Chips";
price = "25,-";
},
{
name = "Chunky Chips w/ Cheese";
price = "29,-";
},
{
name = "Fish'n'Chips";
price = "89,-";
}
);
Title = " Food";
},
{
Rows = (
{
name = Crisps;
price = "15,-";
},
{
name = "Hot Nuts";
price = "20,-";
},
{
name = Popcorn;
price = "25,-";
}
);
Title = Snacks;
},
{
Rows = (
{
name = "The Ale";
price = "47,-";
},
{
name = Carlsberg;
price = "47,-";
},
{
name = Kilkenny;
price = "47,-";
}
);
Title = "Draught Beer";
}
)
知道为什么TableCell中没有相应的名称和价格吗
cell.textLabel.text = [[[_tableData objectAtIndex: indexPath.section] objectForKey: @"name"] objectAtIndex: indexPath.row];
cell.detailTextLabel.text = [[[_tableData objectAtIndex:indexPath.section] objectForKey:@"price"]objectAtIndex: indexPath.row];
应该是(自由使用文字)
应该是(自由使用文字)
您没有引用名为“行”的键。下面是一个可能的解决方案:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MenuCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
NSDictionary *product = [[[_tableData objectAtIndex:indexPath.section] objectForKey:@"Rows"] objectAtIndex:indexPath.row];
cell.textLabel.text = [product objectForKey:@"name"];
cell.detailTextLabel.text = [product objectForKey:@"price"];
return cell;
}
您没有引用名为“行”的键。下面是一个可能的解决方案:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MenuCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
NSDictionary *product = [[[_tableData objectAtIndex:indexPath.section] objectForKey:@"Rows"] objectAtIndex:indexPath.row];
cell.textLabel.text = [product objectForKey:@"name"];
cell.detailTextLabel.text = [product objectForKey:@"price"];
return cell;
}
这是一个很好的例子,说明了为什么不应该在一行上有这么长的嵌套方法调用。您的线路:
cell.textLabel.text = [[[_tableData objectAtIndex: indexPath.section] objectForKey: @"name"] objectAtIndex: indexPath.row];
应该是:
NSDictionary *sectionData = _tableData[indexPath.section];
NSArray *rowsData = sectionData[@"Rows"];
NSDictionary *rowData = rowsData[indexPath.row];
NSString *name = rowData[@"name"];
NSString *price = rowData[@"price"];
cell.textLabel.text = name;
cell.detailTextLabel.text = price;
按照您的方式,您忘记了获取行的数据
像我这样把线路分开有很多好处。对于每个单元格,没有理由必须多次查找节数据、行数据和行数据。所以这更有效。拆分代码也使调试更容易,阅读也更容易。这是一个很好的例子,说明了为什么不应该在一行上有这么长的嵌套方法调用。您的线路:
cell.textLabel.text = [[[_tableData objectAtIndex: indexPath.section] objectForKey: @"name"] objectAtIndex: indexPath.row];
应该是:
NSDictionary *sectionData = _tableData[indexPath.section];
NSArray *rowsData = sectionData[@"Rows"];
NSDictionary *rowData = rowsData[indexPath.row];
NSString *name = rowData[@"name"];
NSString *price = rowData[@"price"];
cell.textLabel.text = name;
cell.detailTextLabel.text = price;
按照您的方式,您忘记了获取行的数据
像我这样把线路分开有很多好处。对于每个单元格,没有理由必须多次查找节数据、行数据和行数据。所以这更有效。拆分代码也使调试更容易,阅读也更容易。是否选中1。代表们接到电话。2.所有学员打印正确的值?您是否检查了1。代表们接到电话。2.所有学员打印正确的值?非常感谢。我必须同意你的观点——这本书更容易阅读,尤其是对我来说,来自C#和Java非常感谢。我必须同意你的观点——这本书更容易阅读,尤其是对我来说,来自C#和Java谢谢。很好用,但还是接受了玛迪的建议,因为我更容易阅读谢谢。很好用,但还是接受了玛迪的建议,因为我更容易阅读谢谢。很好用,但还是接受了玛迪的建议,因为我更容易阅读谢谢。这本书写得很好,但还是采纳了玛迪的建议,因为它更容易让我阅读