【发布时间】:2013-11-13 13:02:26
【问题描述】:
有几个问题与此类似,但我就是不知道如何处理。
我正在解析一个类似于这个的xml;
标题-a 内容-b 类别-cat1
标题-c 内容-d 类别-cat2
等等..
然后我将捕获的所有值保存到 nsmutable 数组中。所以我有标题、内容和类别的 nsmutable 数组。例如,数组中该对象的所有值的索引为 10 的对象([title indexOfObject: 10],[内容 indexOfObject:10],[类别 indexOfObject:10])
解析后,我得到这个循环有多少类别;
mySections=[[NSMutableArray alloc] init];
for (int i=0; i<[category count]; i++) {
if (![mySections containsObject:[category objectAtIndex:i]]) {
[mySections addObject:[category objectAtIndex:i]];
}
}
//--------------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return [mySections count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger count=0;
for (int i=0; i<[baslik count]; i++) {
if ([[category objectAtIndex:i]isEqualToString:[category objectAtIndex:section]]) {
count++;
}
}
return count;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [mySections objectAtIndex:section];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//But in this function I cannot figure out how to access the right element
[title objectAtIndex:indexPath.row]
}
我知道我可能做错了,但这是我第一次为部分编码。有人可以帮助我如何以正确的方式编写它吗?
【问题讨论】:
标签: ios iphone objective-c uitableview sections