Я сохраняю некоторые данные, которые пользователь вводит в файл данных, используя SQLITE, я сохраняю дату, время, чтение и заметку следующим образом:
//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];
Моя проблема или вопрос: я хочу отсортировать данные в uitableview с датой в качестве заголовка раздела и других входных данных в разделе в ячейке. Даты представляют количество секций, которые у меня были бы.
Вот что у меня сейчас:
- (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 - массив, в который я загружаю все данные; у него есть все данные:
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];
Как я могу иметь несколько разделов на основе дат, когда у меня есть только один массив, который readingsArray, который имеет все данные. не могу создать массив дат, потому что это сбивает меня с толку. Разделы дат будут иметь несколько чтений в течение этого дня.
Есть предложения или мысли? Я могу предоставить больше кода или объяснения о моем коде, если это необходимо.