views:

208

answers:

2

Pleaseeee if you guys can help me or point me on the right direction, I would really appreciate.

I am saving some data the user inputs into a data file using SQLITE, I am saving date, time, reading, and a note, as the following:

//Create a Reading Object Readings *readingObj = [[Readings alloc] initWithPrimaryKey:0]; readingObj.date = date.text; readingObj.time = time.text; readingObj.reading = reading.text; readingObj.note = note.text;

//Add the object //This is where I add the inputs to the SQL data file [appDelegate addReading:readingObj];

My problem or question is: I want to sort the data in a uitableview with date as the section header and other inputs under the section in a cell. The dates represent the number of sections I would have.

This is what I have for now:

  • (NSInteger)numberOfSectionsInTableView:(UITableVie w * )tableView { return 1; }

  • (NSInteger)tableView:(UITableView * )tableView numberOfRowsInSection:(NSInteger)section { return [appDelegate.readingsArray count]; }

  • (UITableViewCell * )tableView:(UITableView * )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

HistoryCell *cell = (HistoryCell * )[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) { cell = [[[HistoryCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; }

//Get the object from the array. Readings *readingObj = [appDelegate.readingsArray objectAtIndex:indexPath.row];

[cell setTodo:readingObj]; return cell; }

readingsArray is the array where I load all the data to; it has all the data:

NSInteger primaryKey = sqlite3_column_int(selectstmt, 0); Readings *readingObj = [[Readings alloc] initWithPrimaryKey:primaryKey]; readingObj.date = [NSString stringWithUTF8String:(char * )sqlite3_column_text(selectstmt, 1)]; ////change to int readingObj.time = [NSString stringWithUTF8String:(char * )sqlite3_column_text(selectstmt, 2)]; //// readingObj.reading = [NSString stringWithUTF8String:(char * )sqlite3_column_text(selectstmt, 3)]; //// readingObj.note = [NSString stringWithUTF8String:(char * )sqlite3_column_text(selectstmt, 4)];

[appDelegate.readingsArray addObject:readingObj]; [readingObj release];

How can I have mutliple sections based on the dates, when I only have one array, which readingsArray that has all the data. couldn't make a dates array cuz it was confusing for me. The dates sections would have multiple readings during that day.

Any suggestions or thoughts pleaseeeeeeeeeee!!!!! I can provide more code or explaination about my code if needed.

A: 

In the title you mentioned once core data. So you probably have a NSFetchedResultsController in your delegate that fetches all the appropriate objects from core data! Then you should set a NSFetchedResultsController property in your class and set it to the delegates fetchedresultscontroller, so you have can use the fetchedresultscontroller delegate methods very comfortable. Or you just initialize another fetchedresultscontroller. Why do you set the fetchedresultsc. not directly in your tableviewcontroller class?

burki
A: 

No, I am not using NSFetchedResultsController at all, I tried to but it was confusing for me and I didn't find a good tutorial for it.

I am saving the data in a SQL database table, so my problem now is: How can I save data of the same day under a separate array and for a new day data will be saved in a new different array, maybe that will work. Maybe not! What do you suggest?

salim