Note that there are some explanatory texts on larger screens.

plurals
  1. POdisplay the returned values in section header
    text
    copied!<p>i am working on an expense tracker kind of application.i am able to store and retrieve sorted data perfectly using coredata.</p> <p>i am storing date.i am able to retrieve date in a sorted order.but i want to the date in the section header and related data in that table.</p> <p>ex: Dec 31st 2011 ---------> Section Header<br> xxxxxxx yyyyyy ----->cell with labels </p> <p>Jan 1st 2012---------->Section Header<br> xxxxxxx yyyyyy ------>cell with labels.</p> <p>i am able to receive the dates in a sorted order.but how to display them in a section header in a sorted order and how to declare the number of sections in tableView-noOfSections method?</p> <p>//Code i used for retrieving data.</p> <pre><code>- (void)viewDidLoad { AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate]; NSManagedObjectContext *context = [appDelegate managedObjectContext]; NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"NewExpense" inManagedObjectContext:context]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init]; NSSortDescriptor *date = [[NSSortDescriptor alloc]initWithKey:@"date" ascending:NO]; NSArray *sortDescriptors = [[NSArray alloc]initWithObjects:date,nil]; [fetchRequest setSortDescriptors:sortDescriptors]; [fetchRequest setEntity:entityDesc]; NSError *error; self.listOfExpenses = [[context executeFetchRequest:fetchRequest error:&amp;error]retain] [fetchRequest release]; [super viewDidLoad]; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1;// as of now i have taken one. } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { [self.listOfExpenses count];  } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //labels are created and added to the cell's subview. NSManagedObject *records = nil; records = [self.listOfExpenses objectAtIndex:indexPath.row]; self.firstLabel.text = [records valueForKey:@"category"]; NSString *dateString = [NSString stringWithFormat:@"%@",[records valueForKey:@"date"]]; NSString *dateWithInitialFormat = dateString; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"]; NSDate *date = [dateFormatter dateFromString:dateWithInitialFormat]; [dateFormatter setDateFormat:@"dd-MM-yyyy"]; NSString *dateWithNewFormat = [dateFormatter stringFromDate:date]; self.secondLabel.text = dateWithNewFormat; NSString *amountString = [NSString stringWithFormat:@"%@",[records valueForKey:@"amount"]]; self.thirdLabel.text = amountString; totalAmount = totalAmount + [amountString doubleValue]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload