2010-02-08 30 views
-1

我使用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具有所有數據。無法創建日期數組,因爲它讓我感到困惑。日期部分在那一天會有多個讀數。

任何建議或想法?如果需要,我可以提供更多關於我的代碼的代碼或解釋。

回答

0

在標題中你提到過一次核心數據。所以你可能在你的委託中有一個NSFetchedResultsController,它從核心數據中獲取所有適當的對象!然後,你應該在你的類中設置一個NSFetchedResultsController屬性,並將它設置爲代表fetchedresultscontroller,這樣你就可以使用fetchedresultscontroller委託方法非常舒服。或者你只是初始化另一個fetchedresults控制器。你爲什麼設置fetchedresultsc。不是直接在你的tableviewcontroller類中?