簡體   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