繁体   English   中英

pList中的分段UITableView可以深入到子视图

[英]Sectioned UITableView from pList that can drill down into children sub views

我真的很不敢问这个问题,因为有人帮助了我一半,但是我真的想尽办法解决这个问题。

基本上我想要一个分段的UITableView从pList文件加载其数据,该文件可以向下钻取到子视图。

如前所述,有人足够帮助我从pList中获取Sectioned UITableView,但我不知道如何进行深入研究

他提供给我的继承人

我会在这里显示它,但我不太了解如何显示代码,而不会看起来令人恶心= /

您可以在更深层次上重复相同的技巧。 即,具有单独的名为“ Section1Row1.plist”,“ Section2Row2.plist”等的plist文件。然后,您可以重用相同的视图控制器类,但根据用户所做的选择来确定要加载的plist文件的名称。

另一种方法是将所有内容存储在一个大的plist文件中。 然后,每个选项(行)都将成为字典,其中包含标题和全新的层次结构(如原始结构)。 然后,将新视图控制器的“根”数组设置为所选的选项,如我在下面的示例代码和plist中所示。

如果您有很多选择或级别,则任何一种方法都会变得混乱。

- (void) viewDidLoad
{
    [super viewDidLoad];
    if (!self.tableData)
    {
        self.tableData = [NSArray arrayWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"Table" ofType: @"plist"]];
        self.title = @"Root";
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.text = [[[[tableData objectAtIndex: indexPath.section] objectForKey: @"Rows"] objectAtIndex: indexPath.row] objectForKey: @"Title"];
    return cell;
}

- (void) tableView: (UITableView*) tableView didSelectRowAtIndexPath: (NSIndexPath*) indexPath;
{
    RootViewController* nextViewController = [[[RootViewController alloc] initWithNibName: @"RootViewController" bundle: nil] autorelease];
    NSDictionary* rowData = [[[tableData objectAtIndex: indexPath.section] objectForKey: @"Rows"] objectAtIndex: indexPath.row];
    NSArray* subtree = [rowData objectForKey: @"Subtree"];
    nextViewController.tableData = subtree;
    nextViewController.title = [rowData objectForKey: @"Title"];

    [self.navigationController pushViewController: nextViewController animated: YES];
}


<?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>Title</key>
                <string>Row1</string>
                <key>Subtree</key>
                <array/>
            </dict>
            <dict>
                <key>Title</key>
                <string>Row2</string>
                <key>Subtree</key>
                <array>
                    <dict>
                        <key>Title</key>
                        <string>Table2Section1</string>
                        <key>Rows</key>
                        <array>
                            <dict>
                                <key>Title</key>
                                <string>Row1</string>
                                <key>Subtree</key>
                                <array/>
                            </dict>
                            <dict>
                                <key>Title</key>
                                <string>Row2</string>
                                <key>Subtree</key>
                                <array/>
                            </dict>
                        </array>
                    </dict>
                </array>
            </dict>
        </array>
    </dict>
</array>
</plist>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM