There are several questions similar to this one but I just cannot figure out how to deal with them.
I'm parsing an xml similar to this one;
title-a content-b category-cat1
title-c content-d category-cat2
and so on..
Then I save all the values I catch into the nsmutable arrays .. So I have nsmutable arrays of title, content and category.an object for example index of 10 all the values for that object in the arrays ( [title indexOfObject:10],[content indexOfObject:10],[category indexOfObject:10] )
After the parsing I get how many category I have with this loop;
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]
}
I know maybe I'm doing it wrong but this is the first time im coding for section.Can someone help me how can I write it in a right way?