UITableView分组和.plist [英] UITableView grouped and .plist

查看:65
本文介绍了UITableView分组和.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 ìmagethe 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显示Rows中包含的>键作为单元格的标题.我尝试过

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?

推荐答案

您的plistdictionaries的数组.每个dictionary代表一个section. 在section/dictionary中,section中的rows作为arrayarray存在. 因此,要在特定的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆