UITableView分组和.plist [英] UITableView grouped and .plist
问题描述
我想使用plist创建一个分段的UITableView. 最初,我的plist是这样构造的:
I wanted to make a sectioned UITableView using plist. Originally, my plist was structured this way:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>name</key>
<string>First</string>
<key>description</key>
<string>First</string>
<key>image</key>
<string>image.png</string>
</dict>
<dict>
<key>name</key>
<string>Second</string>
<key>description</key>
<string>SecondR</string>
<key>image</key>
<string>image.png</string>
</dict>
//etc
</array>
</plist>
name
是我的detailView
中的行名和rowNamed
标签的名称,描述是针对我的‘detailView and ìmage
UIImageView中的字符串.
Where name
was the name of the rows and of the rowNamed
label in my detailView
, description was for the string in my ´detailViewand ìmage
the UIImageView in the detailView
.
cell.textLabel.text确实以这种方式显示了name
键:
The cell.textLabel.text did show the name
key this way:
cell.textLabel.text = [[sortedList objectAtIndex:indexPath.row]objectForKey:@"name"];
现在,按照此问题的答案,从pList提取的UITableView部分,我创建了带有部分的新plist文件,其结构如下:
Now,following the answer in this question, sectioned UITableView sourced from a pList, I created my new plist file with section, structured this way:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>Title</key>
<string> Section1</string>
<key>Rows</key>
<array>
<dict>
<key>name</key>
<string>Test</string>
<key>description</key>
<string>test</string>
<key>image</key>
<string>testtttt</string>
</dict>
</array>
</dict>
<dict>
<key>Title</key>
<string> Section2</string>
<key>Rows</key>
<array>
<dict>
<key>name</key>
<string>Test</string>
<key>description</key>
<string>test</string>
<key>image</key>
<string>testtttt</string>
</dict>
</array>
</dict>
</array>
</plist>
问题在于,现在我不知道如何使其类似于先前的plist结构(我的意思,图像,名称和描述),并且我不知道如何使cellForRowAtIndexPath
显示
The point is that now i don't know how to make it similar to the previous plist structure (i mean, image,name and description), and i don't know how to make cellForRowAtIndexPath
show the name
key contained in Rows
as title of the cells. I tried with
cell.textLabel.text = [[[sortedList objectAtIndex: indexPath.section] objectForKey: @"name"]objectAtIndex:indexPath.row];
但是我有一个空的牢房.
But i get an empty cell.
我希望cell.textLabel.text显示每个部分中包含的每个元素(行)的键name
有人能帮我吗?
I want cell.textLabel.text to show the key name
for each element (row) contained in each section
Can someone help me?
推荐答案
您的plist
是dictionaries
的数组.每个dictionary
代表一个section
.
在section
/dictionary
中,section
中的rows
作为array
的array
存在.
因此,要在特定的section
中获取row
,请首先获取section
.然后使用objectForKey:@"Rows"
获取row
.
Your plist
is an array of dictionaries
. Each dictionary
represents a section
.
And rows
within a section
is present as an array
whose key
is Rows
in that section
/dictionary
.
So to get a row
in a particular section
, first get the section
. Then get the row
using objectForKey:@"Rows"
.
一旦您有行array
,它就会再次包含多个rows
作为dictionary
.
Once you have rows array
, it again contains the several rows
as a dictionary
.
NSDictionary *section = [sortedList objectAtIndex:indexPath.section];
NSArray *rows = [section objectForKey:@"Rows"];
cell.textLabel.text = [[rows objectAtIndex:indexPath.row] objectForKey:@"name"];
这篇关于UITableView分组和.plist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!