我在特定用户的数据库中有 100 多条记录。现在我只想显示其中的前 30 条,当按下“更多”按钮时,它们下方会出现 30 条以上的记录。如何在 iPhone 应用程序中执行此操作?
user1600593
问问题
72 次
2 回答
0
您可以使用 SQL 查询来实现您的目标
-(NSMutableArray *)SelectResult:(int)offset
{
NSMutableArray *arrdata;
arrdata=[[NSMutableArray alloc]init];
sqlite3 *database;
NSString *databasePath = [self getDBPath];
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
NSString *sqlQuery=[NSString stringWithFormat:@"Select * from TableName where RecordId > %d and RecordId <=%d",offset,offset+30];
sqlite3_stmt *compiledStatement;
compiledStatement=nil;
if(sqlite3_prepare_v2(database, [sqlQuery UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK)
{
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{
if ((char *)sqlite3_column_text(compiledStatement,0)!=0)
{
NSMutableDictionary *temData = [[NSMutableDictionary alloc] init];
int pKey = sqlite3_column_int(compiledStatement,0);
[temData setValue:[NSString stringWithFormat:@"%d",pKey] forKey:@"RecordId"];
[arrdata addObject:temData];
}
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
return arrdata;
}
请调用此方法并将偏移量作为整数传递,它将为您提供从偏移量记录的 30
比如offset = 0 然后 1 到 30 offset = 30 然后 31 到 60等等....
希望对你有帮助
快乐编码
于 2012-12-13T13:44:23.167 回答
0
只需使用 aNSMutableArray
来保存您的数据。datasource
如果要显示更多记录,请确保在您的表格视图中显示一个额外的单元格(带有“更多”消息)。
然后,didSelectRowAtIndexPath
您可以通过从数据库中添加其他记录来修改表视图的数据数组。
您可以根据数据数组的大小动态生成 SQL 查询。
于 2012-12-13T13:46:35.240 回答