2010-02-08 59 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类中?