UItableView引用核心数据中的部分:

问题描述 投票:-1回答:1

我正在使用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包含所有数据。无法制作日期数组因为它让我感到困惑。日期部分在那一天会有多个读数。

有什么建议或想法?如果需要,我可以提供更多关于我的代码的代码或解释。

sql iphone database uitableview
1个回答
0
投票

在标题中,您提到过一次核心数据。因此,您的委托中可能有一个NSFetchedResultsController,它从核心数据中获取所有适当的对象!然后你应该在你的类中设置一个NSFetchedResultsController属性并将其设置为委托fetchedresultscontroller,这样你就可以非常舒服地使用fetchedresultscontroller委托方法。或者你只是初始化另一个fetchedresultscontroller。为什么要设置fetchedresultsc。不是直接在你的tableviewcontroller类?

© www.soinside.com 2019 - 2024. All rights reserved.