我使用SQLite保存一些數據的用戶輸入到數據文件,我保存日期,時間,讀書,和一張紙條,如下所示:UITableView的引用部分:
//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具有所有數據。無法創建日期數組,因爲它讓我感到困惑。日期部分在那一天會有多個讀數。
任何建議或想法?如果需要,我可以提供更多關於我的代碼的代碼或解釋。