Sorry to ask again the question with full description.What i have that i have resultsArray which has title description etc which gets from server but problem is that i want to show this data in sections.
So lets say if have three sections which are coming from array then how will populate the data in each section using single resultArray.
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [categoryArray objectAtIndex:section];
}
resutArray has all the data for all sections so how to show according to sections
Structure of array is
ObjectData *theObject =[[ObjectData alloc] init];
[theObject setCategory:[dict objectForKey:@"category"]];
[theObject setSub_Category:[dict objectForKey:@"sub_Category"]];
[theObject setContent_Type:[dict objectForKey:@"content_Type"]];
[theObject setContent_Title:[dict objectForKey:@"content_Title"]];
[theObject setPublisher:[dict objectForKey:@"publisher"]];
[theObject setContent_Description:[dict objectForKey:@"content_Description"]];
[theObject setContent_ID:[dict objectForKey:@"content_ID"]];
[theObject setContent_Source:[dict objectForKey:@"content_Source"]];
[resultArray addObject:theObject];
Do same as in the sample code
Using custom class you can achieve this.
myClass.h
myClass.m
First you need to set up your resultArray with above class object. Set Appropriate value for class. Example:
Now Set
numberOfSectionsInTableView
,numberOfRowsInSection
,titleForHeaderInSection
,cellForRowAtIndexPath
You might also find it much easier to use the free Sensible TableView framework. The framework will simply take your array and generate all the table view cells and sections, including all the detail views if you wish. I find it much simpler and literally takes a few minutes to implement.
Look's like you have ObjectData which has attribute called category, and you want to show table view with ObjectData's grouped by categories. You may do this generating an NSDictionary with key = unique category, and value = NSArray of ObjectData of that category. Then you use that NSDictionary as a data for datacource.
Then in your controller:
Note that that's just an example for you, you may optimize this as you want.
If all you have is an NSMutableArray and you want to split it into sections means you have to know index of objects. For example,
in 1st sections display data from 0 to 2 index, in 2nd from 3 to 5 index, in 3rd from 6 to 8 index.
Else better go for
NSDictionary
. Keep section title as key and the values as NSArray in Dictionary. So it will be easier to load the cell.You have NSArray Of Object Data.. So you can do it as
So now you will have required data...