Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITableView,包含节和已解析数据如何创建cellForRowAtIndexPath_Iphone_Xcode_Uitableview_Nsxmlparser - Fatal编程技术网

Iphone UITableView,包含节和已解析数据如何创建cellForRowAtIndexPath

Iphone UITableView,包含节和已解析数据如何创建cellForRowAtIndexPath,iphone,xcode,uitableview,nsxmlparser,Iphone,Xcode,Uitableview,Nsxmlparser,我在设置cellForRowAtIndexPath和分区时遇到问题。如果我只显示所有的“轨迹”,而不按“主题”分隔各个部分,那么效果很好 Track *aTrack = [appDelegate.tracks objectAtIndex:row]; cell.textLabel.text = aTrack.track_title; 我已经在TableView中设置了我的NumberOfSection,numberOfRowsInSection,HeaderInSection的Title。这些都

我在设置cellForRowAtIndexPath和分区时遇到问题。如果我只显示所有的“轨迹”,而不按“主题”分隔各个部分,那么效果很好

Track *aTrack = [appDelegate.tracks objectAtIndex:row];
cell.textLabel.text = aTrack.track_title;
我已经在TableView中设置了我的NumberOfSection,numberOfRowsInSection,HeaderInSection的Title。这些都很好用。但我真的不知道如何设置CellForRowatineXpath

在进一步研究之后,最好的方法似乎是使用NSDictionary来显示我的单元格

NSDictionary *dictionary = [sectionTopicArray objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"Tracks"];
NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
有人能给我一些关于如何制作一个能容纳我所有字典的可变数组(sectionTopicArray)的建议吗?我能在脑海中看到以下内容,但就是不知道如何用代码来表达

sectionTopicArray
[0] Dictionary 1 with key Tracks
    Track1
    Track2
    Track3
[1] Dictionary 2 with key Tracks
    Track4
[2] Dictionary 3 with key Tracks
    Track5
    Track6

basically I'm thinking...
Section0 = Dictionary1 = Topic1 
Section1 = Dictionary2 = Topic2 
Section2 = Dictionary3 = Topic3

我会使用嵌套数组

创建数据阵列:

    NSArray *dataArray = [NSArray arrayWithObjects:
                      [NSArray arrayWithObjects:    // Section 0
                       track1,                      //  Item 0
                       track2,                      //  Item 1
                       track3,                      //  Item 2  (indexpath 0.2)
                       nil],
                      [NSArray arrayWithObjects:    // Section 1
                       track4,                      //  Item 0  (indexpath 1.0)
                       nil],
                      [NSArray arrayWithObjects:    // Section 2
                       track5,                      // Item 0
                       track6,                      // Item 1   (indexpath 2.1)
                       nil],
                      nil];
cellForRowAtIndexPath中的访问对象:

Track *trackAtIndexPath = [[dataArray objectAtIndex:indexpath.section] objectAtIndex:indexpath.row];
您可以这样创建章节标题:

    NSArray *sectionTitles = [NSArray arrayWithObjects:
                          @"Section 0",
                          @"Section 1",
                          @"Section 2",
                          nil];

应该清楚如何访问它们。

轨道数据在哪里?它是在设备上的SQLite数据库中,还是驻留在内存中,还是根据需要从网络中获取?@johnitsXML解析。谢谢谢谢你的回复。嗯……当然,我也想过。但是,在循环中,您将如何做到这一点。由于我的数据不是静态的,如果XML发生更改或更新,数据可能会发生更改。您只需使用NSMutableArray而不是那些NSArray,就可以遍历数据并将其添加到正确的位置。您可以使用
[[dataArray objectAtIndex:section]addObject:track]
或类似的方法将曲目添加到分区中。如果必须向dataArray中不存在的节添加数据,只需添加相应的节数组
[dataArray addObject:[NSMutableArray]]