views:

39

answers:

2

I need to develop an rss parser with a tableview as the first view and detail view as we select a row in table.

But the thing is, i need to group the feeds in table view based on publishing date and titleForHeaderInSection as the publishing date. That is there should be many sections of rss feed based on date.

With each feed there is a publishing date

I have no idea abt adding sections in tableview.

Please help. Sorry if the information is not sufficient.

+1  A: 

to manage number of Sections in TableView use

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return noOfSections;
}

to calculates the number of rows in a specific section

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {  
       // return no of rows in specific section
 }

in tableView:cellForRowAtIndexPath: method, extract both the section and row from the index path and use that to manage your data.

for managing title For Header in Section use

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    // return titleForHeader;
}
Gyani
dat s good ... is there a need to implement below methods?- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
suslovjb
no - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section method is sufficient
Gyani
ok. then how does corresponding rows move to their respective sections???? for eg. for 1st section there may b 5 feeds which form a single section. and 2nd sectoin there may b another no. of feeds. and so on.
suslovjb
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section is there to manage no of rows in each section'
Gyani
ok tank u for that.. evrythng clear. if u get the logic of how to group it using pub date pls inform me.. tank u for ur help. also tanks to Benoît
suslovjb
A: 

You can make a dictionary of array. The key will be the dates, and the object, an array of rss item. Then I will sort the dictionary key to an array to have the date ordered.

In the table view source delegate:

  • numberOfSectionsInTableView: will be the number of date in the sort array, or the nomber of entry in the dictionary
  • tableView:titleForHeaderInSection: will be the date in the sort array
  • tableView:numberOfRowsInSection: will be the number of rss item in the dictionary for the key of the sort array item
Benoît
NSSortDescriptor *sortDesc = [NSSortDescriptor sortDescriptorWithKey:@"Pub date" ascending:YES]; [root sortUsingDescriptors:[NSArray arrayWithObject:sortDesc]]; [self.root sortUsingDescriptors:states]; is it the way?
suslovjb