【问题标题】:Having Trouble with Mutable Array to load sections in a Table View from Plist使用可变数组从 Plist 加载表视图中的部分时遇到问题
【发布时间】:2009-10-26 00:47:36
【问题描述】:

在 AppDelegate 中加载的 Plist 具有以下结构:

根 ----> 字典

测试项目---->数组

第 1 项 ----> 字典

HeaderTitle ----> 字符串 ----> 第 1 节

项目 ----> 数组

第 1 项 ----> 字典

名字 ----> 字符串 ----> 任何名字

SecondName ----> String ----> 另一个名字

CellIcon ----> 字符串 ----> Icon.gif

查看---->编号---->2

第 2 项 ----> 字典

名字 ----> 字符串 ----> 任何名字 2

SecondName ----> String ----> 另一个名字 2

CellIcon ----> 字符串 ----> Icon2.gif

查看---->编号---->2

我有一个 TableViewController.m,它要求我将上述 plist 结构放在一个有 5 个部分的表视图中。问题是我无法在表格视图的描述部分中显示该数据。我在编写一个可变数组来完成这项任务时感到困惑。我已经在使用数组来控制表中的不同级别(视图),但是我无法添加可变数组来控制表的各个部分。我的代码如下:

- (void)viewDidLoad {
[super viewDidLoad];

if (CurrentLevel == 0) {
    NSArray *tempArray = [[NSArray alloc] init];
    self.tableDataSource = tempArray;
    [tempArray release];

    TheAppDelegate *AppDelegate = (TheAppDelegate *)[[UIApplication sharedApplication] delegate];
    self.tableDataSource = [AppDelegate.data objectForKey:@"SampleArray"];
    self.navigationItem.title = @"Main";

          }
      else 
    self.navigationItem.title = CurrentTitle;   
          }

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; 
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [menuSections count];
}

- (NSString *)tableView:(UITableView *)tableView     titleForHeaderInSection:(NSInteger)section {
NSDictionary *menuSection = [menuSections objectAtIndex:section];
return [menuSection objectForKey:@"HeaderTitle"];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section     {
NSArray *menuItems = [[menuSections objectAtIndex:section] objectForKey:@"Items"];
return [menuItems count];
}

【问题讨论】:

    标签: iphone arrays plist tableview


    【解决方案1】:

    您的代码看起来没有问题,当输入这些方法时,您确定您的数组中有数据吗?

    【讨论】:

    • 是的..我的 plist 中有数据。尽管此代码可以编译,但我的应用程序在转到 tableview 时会崩溃。任何帮助表示赞赏。
    • 您在 viewDidLoad 中设置了 tableDataSource,但是 menuSections 是如何从中构建的呢?我认为我们需要更多资源。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多