Ios plist的索引部分
我有一个plist,我正试图把它分成几个部分。我有一切设置,它是工作的,但有一件事我不能设置的数字rowsinssection count。此时,它仅显示第一部分“b”,如图所示 我遇到的问题是,我正在使用plist填充表,但无法计算如下所示的节数。还需要按字母顺序对表格进行排序Ios plist的索引部分,ios,Ios,我有一个plist,我正试图把它分成几个部分。我有一切设置,它是工作的,但有一件事我不能设置的数字rowsinssection count。此时,它仅显示第一部分“b”,如图所示 我遇到的问题是,我正在使用plist填充表,但无法计算如下所示的节数。还需要按字母顺序对表格进行排序 // Find out the path of recipes.plist NSString *path = [[NSBundle mainBundle] pathForResource:@"laws" of
// Find out the path of recipes.plist
NSString *path = [[NSBundle mainBundle] pathForResource:@"laws" ofType:@"plist"];
// Load the file content and read the data into arrays
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
//Load Data into Array
self.tableData = [dict objectForKey:@"Laws"];
self.tableIndexData = [dict objectForKey:@"index"]; //containing the index
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// NSString *sectionTitle = [self.tableIndexData objectAtIndex:section];
// NSArray *sectionAnimals = [self.tableData objectForKey:sectionTitle];
return [self.tableData count];
}
多节表通常是数组中的数组,或字典数组中的数组。很难看出代码中是否存在这种情况,因为@Law键控对象的结构在您显示的代码中并不明显。如果您在plist中显示存储的数据,人们将更容易帮助您 从代码对象来看,@Laws似乎是一个数组1级别,而不是一个数组数组或一个嵌套数组的字典。您的代码背叛了结构:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection (NSInteger)section
{
// NSString *sectionTitle = [self.tableIndexData objectAtIndex:section];
// NSArray *sectionAnimals = [self.tableData objectForKey:sectionTitle];
return [self.tableData count];
}
您首先需要做的是使用嵌套数组或具有嵌套数组的字典数组创建正确的结构
一旦有了该结构,tableviewNumberOfRowsInSection的代码对于具有嵌套数组的字典数组应该是这样的:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return ([font_family_array count]);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSDictionary *dictionary = [font_family_array objectAtIndex:section];
NSArray *array = [dictionary objectForKey:@"array"];
NSInteger count = [array count];
return (count);
}
然后,要设置节标题,请执行以下操作:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSDictionary *dict = [font_family_array objectAtIndex:section];
NSString *title1 = [dict objectForKey:@"family"];
return (title1);
}
在下面的示例中,font_family_数组是一个包含2个元素的字典数组
@族包含标题/标题,@array包含嵌套数组或内容。如前所述,阵列阵列也是可能的