Iphone 无法使用正确的计数和数据填充tableview节/行。从plist文件

Iphone 无法使用正确的计数和数据填充tableview节/行。从plist文件,iphone,objective-c,ios,Iphone,Objective C,Ios,我在项目的最后几天遇到了一点小麻烦。问题是,我试图用从用户创建的可编辑plist文件读取的部分填充我的表视图 当前,未分组的单元格填充良好。这些细胞甚至彼此相邻。 但是,我想做的是为每个组创建部分(按标题) 所以第一节都有第一节的标题。第二节也会这样做。 我得到的是所有组中所有相同的标题(单元格) 我已经为标题创建了部分,并在标题中显示这些标题 我认为我的问题是如何填充RowsFlosections和cellForRows 这里有几个代码剪贴 我将数据从plist拉入一个数组,然后在ViewDi

我在项目的最后几天遇到了一点小麻烦。问题是,我试图用从用户创建的可编辑plist文件读取的部分填充我的表视图

当前,未分组的单元格填充良好。这些细胞甚至彼此相邻。 但是,我想做的是为每个组创建部分(按标题)

所以第一节都有第一节的标题。第二节也会这样做。 我得到的是所有组中所有相同的标题(单元格)

我已经为标题创建了部分,并在标题中显示这些标题

我认为我的问题是如何填充RowsFlosections和cellForRows

这里有几个代码剪贴

我将数据从plist拉入一个数组,然后在ViewDidDisplay中像这样对其进行排序

self.accessDataArray = [[NSMutableArray alloc]initWithContentsOfFile:appDelegate.pathToUserCopyOfPlist];

NSSortDescriptor * descriptor = [NSSortDescriptor sortDescriptorWithKey:@"ProjectID" ascending:YES];
[accessDataArray sortUsingDescriptors:[NSArray arrayWithObject:descriptor]];
然后,我合并数组以删除重复的部分计数和标题,如下所示

mutset = [[NSMutableSet alloc] init ];

if ([accessDataArray count]>1) {

    for (i = 0; i < [accessDataArray count]; i++) {
        [mutset addObject:[[accessDataArray objectAtIndex:i]objectForKey:@"ProjectID"]];
        NSLog(@"mutable count = %d",[mutset count]);

       }
    }

    setToArray = [[NSArray alloc]initWithSet:mutset];
    NSLog(@" setarray count = %d",[setToArray count]);

    for (int m = 0; m < [mutset count]; m++) {
      NSLog(@"new array %@",[setToArray objectAtIndex:m]);
    }`
以下是应用程序生成的调试日志:

2011-09-16 12:06:52.318 LockPin[617:b303] object at index 0: Main
2011-09-16 12:06:52.320 LockPin[617:b303] object at index 1: Main
2011-09-16 12:06:52.321 LockPin[617:b303] object at index 2: Main
2011-09-16 12:06:52.322 LockPin[617:b303] object at index 3: New Prop
2011-09-16 12:06:52.324 LockPin[617:b303] object at index 4: New Prop
2011-09-16 12:06:52.326 LockPin[617:b303] object at index 5: Not Main
2011-09-16 12:06:52.327 LockPin[617:b303] object at index 6: Not Main
2011-09-16 12:06:52.327 LockPin[617:b303] object at index 7: Store
2011-09-16 12:06:52.328 LockPin[617:b303] object at index 8: Store
2011-09-16 12:06:52.328 LockPin[617:b303] object at index 9: Store
2011-09-16 12:06:52.329 LockPin[617:b303] object at index 10: all doors
2011-09-16 12:06:52.332 LockPin[617:b303] object at index 11: all doors
2011-09-16 12:06:52.333 LockPin[617:b303] mutable count = 1
2011-09-16 12:06:52.333 LockPin[617:b303] mutable count = 1
2011-09-16 12:06:52.334 LockPin[617:b303] mutable count = 1
2011-09-16 12:06:52.334 LockPin[617:b303] mutable count = 2
2011-09-16 12:06:52.334 LockPin[617:b303] mutable count = 2
2011-09-16 12:06:52.335 LockPin[617:b303] mutable count = 3
2011-09-16 12:06:52.381 LockPin[617:b303] mutable count = 3
2011-09-16 12:06:52.382 LockPin[617:b303] mutable count = 4
2011-09-16 12:06:52.382 LockPin[617:b303] mutable count = 4
2011-09-16 12:06:52.383 LockPin[617:b303] mutable count = 4
2011-09-16 12:06:52.383 LockPin[617:b303] mutable count = 5
2011-09-16 12:06:52.384 LockPin[617:b303] mutable count = 5
2011-09-16 12:06:52.384 LockPin[617:b303]  setarray count = 5
2011-09-16 12:06:52.386 LockPin[617:b303] new array all doors
2011-09-16 12:06:52.386 LockPin[617:b303] new array New Prop
2011-09-16 12:06:52.387 LockPin[617:b303] new array Not Main
2011-09-16 12:06:52.388 LockPin[617:b303] new array Main
2011-09-16 12:06:52.388 LockPin[617:b303] new array Store


好的,我在原来的帖子里修改了密码。她为标题显示了正确数量的章节标题和标题。在每个部分中,我都有每个部分中数组中存在的对象数量(计数)。以下是应用程序使用当前设置生成的调试日志。也许这会有助于了解情况

2011-09-16 12:06:52.318 LockPin[617:b303] object at index 0: Main
2011-09-16 12:06:52.320 LockPin[617:b303] object at index 1: Main
2011-09-16 12:06:52.321 LockPin[617:b303] object at index 2: Main
2011-09-16 12:06:52.322 LockPin[617:b303] object at index 3: New Prop
2011-09-16 12:06:52.324 LockPin[617:b303] object at index 4: New Prop
2011-09-16 12:06:52.326 LockPin[617:b303] object at index 5: Not Main
2011-09-16 12:06:52.327 LockPin[617:b303] object at index 6: Not Main
2011-09-16 12:06:52.327 LockPin[617:b303] object at index 7: Store
2011-09-16 12:06:52.328 LockPin[617:b303] object at index 8: Store
2011-09-16 12:06:52.328 LockPin[617:b303] object at index 9: Store
2011-09-16 12:06:52.329 LockPin[617:b303] object at index 10: all doors
2011-09-16 12:06:52.332 LockPin[617:b303] object at index 11: all doors
2011-09-16 12:06:52.333 LockPin[617:b303] mutable count = 1
2011-09-16 12:06:52.333 LockPin[617:b303] mutable count = 1
2011-09-16 12:06:52.334 LockPin[617:b303] mutable count = 1
2011-09-16 12:06:52.334 LockPin[617:b303] mutable count = 2
2011-09-16 12:06:52.334 LockPin[617:b303] mutable count = 2
2011-09-16 12:06:52.335 LockPin[617:b303] mutable count = 3
2011-09-16 12:06:52.381 LockPin[617:b303] mutable count = 3
2011-09-16 12:06:52.382 LockPin[617:b303] mutable count = 4
2011-09-16 12:06:52.382 LockPin[617:b303] mutable count = 4
2011-09-16 12:06:52.383 LockPin[617:b303] mutable count = 4
2011-09-16 12:06:52.383 LockPin[617:b303] mutable count = 5
2011-09-16 12:06:52.384 LockPin[617:b303] mutable count = 5
2011-09-16 12:06:52.384 LockPin[617:b303]  setarray count = 5
2011-09-16 12:06:52.386 LockPin[617:b303] new array all doors
2011-09-16 12:06:52.386 LockPin[617:b303] new array New Prop
2011-09-16 12:06:52.387 LockPin[617:b303] new array Not Main
2011-09-16 12:06:52.388 LockPin[617:b303] new array Main
2011-09-16 12:06:52.388 LockPin[617:b303] new array Store

假设您要取消对return1的注释//[设置阵列计数];这可能会返回您拥有的“标题”(也称为节)的数量,在numberOfRowsInSection中,您希望返回作为参数传递给您的节的行数。确保在titleForHeaderInSection例程中返回NSString。

很抱歉代码的格式设置不确定为什么从numberOfSectionsInTable返回1,因此表中只有一个节。那么在numberOfRowsInSeciton中,我希望您使用section参数来确定有多少行,但是section参数没有在该方法中使用?好的,我在原始帖子中更改了代码。她为标题显示了正确数量的章节标题和标题。在每个部分中,我都有每个部分中数组中存在的对象数量(计数)。我不太确定您的问题——是数组的显示与数组结构不符,还是无法将数组加载到所需的结构中?是的,显示的单元格与部分不符。我想要的是第0节title=Main,那么只有标题为“Main”的对象才会存在于该节中。我得到的是所有对象填充所有部分。您必须在cellForRowAtIndexPath中进行筛选。基本上,系统会调用cellForRowAtIndexPath,并且您的代码会为系统提供适当的单元格(对象)。因此,将使用nsindepath调用您。index.xpath.section将告诉您必须为哪一节提供信息,而index.xpath.row将告诉您哪一行。因此,请检查cellforrowatinexpath中的indexath参数,并在返回的单元格中提供正确的信息。谢谢,这很有意义。现在只要你能把它打出来…(翻译成代码)
2011-09-16 12:06:52.318 LockPin[617:b303] object at index 0: Main
2011-09-16 12:06:52.320 LockPin[617:b303] object at index 1: Main
2011-09-16 12:06:52.321 LockPin[617:b303] object at index 2: Main
2011-09-16 12:06:52.322 LockPin[617:b303] object at index 3: New Prop
2011-09-16 12:06:52.324 LockPin[617:b303] object at index 4: New Prop
2011-09-16 12:06:52.326 LockPin[617:b303] object at index 5: Not Main
2011-09-16 12:06:52.327 LockPin[617:b303] object at index 6: Not Main
2011-09-16 12:06:52.327 LockPin[617:b303] object at index 7: Store
2011-09-16 12:06:52.328 LockPin[617:b303] object at index 8: Store
2011-09-16 12:06:52.328 LockPin[617:b303] object at index 9: Store
2011-09-16 12:06:52.329 LockPin[617:b303] object at index 10: all doors
2011-09-16 12:06:52.332 LockPin[617:b303] object at index 11: all doors
2011-09-16 12:06:52.333 LockPin[617:b303] mutable count = 1
2011-09-16 12:06:52.333 LockPin[617:b303] mutable count = 1
2011-09-16 12:06:52.334 LockPin[617:b303] mutable count = 1
2011-09-16 12:06:52.334 LockPin[617:b303] mutable count = 2
2011-09-16 12:06:52.334 LockPin[617:b303] mutable count = 2
2011-09-16 12:06:52.335 LockPin[617:b303] mutable count = 3
2011-09-16 12:06:52.381 LockPin[617:b303] mutable count = 3
2011-09-16 12:06:52.382 LockPin[617:b303] mutable count = 4
2011-09-16 12:06:52.382 LockPin[617:b303] mutable count = 4
2011-09-16 12:06:52.383 LockPin[617:b303] mutable count = 4
2011-09-16 12:06:52.383 LockPin[617:b303] mutable count = 5
2011-09-16 12:06:52.384 LockPin[617:b303] mutable count = 5
2011-09-16 12:06:52.384 LockPin[617:b303]  setarray count = 5
2011-09-16 12:06:52.386 LockPin[617:b303] new array all doors
2011-09-16 12:06:52.386 LockPin[617:b303] new array New Prop
2011-09-16 12:06:52.387 LockPin[617:b303] new array Not Main
2011-09-16 12:06:52.388 LockPin[617:b303] new array Main
2011-09-16 12:06:52.388 LockPin[617:b303] new array Store