I have more than 10000+ record in database. I want to load it on a table view. It will take 3 to 4 seconds to fetch all data from database and than load it on table view. Is there is more efficient way to increase the response and load the data in a uitableview? Here is my code for get All Data fro database
我在数据库中有超过10000条记录。我想将它加载到表视图上。从数据库中获取所有数据需要3到4秒,然后将其加载到表视图中。是否有更有效的方法来增加响应并在uitableview中加载数据?这是我的数据库获取所有数据的代码
- (void)getAllData {
NSString * convertInttoStr = [NSString stringWithFormat:@"%d", rowNumber];
// Getting the database path.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *dbPath = [docsPath stringByAppendingPathComponent:@"iandroidquran_database 3.sqlite"];
FMDatabase *database = [FMDatabase databaseWithPath:dbPath];
[database open];
NSString *sqlSelectQuery = [NSString stringWithFormat:
@"SELECT * FROM qSurahContent WHERE surahID=%@" ,
convertInttoStr];
// Query result
FMResultSet *resultsWithNameLocation = [database executeQuery:sqlSelectQuery];
while([resultsWithNameLocation next]) {
NSString *strID = [NSString stringWithFormat:@"%d",[resultsWithNameLocation intForColumn:@"surahID"]];
NSString *strName = [NSString stringWithFormat:@"%@",[resultsWithNameLocation stringForColumn:@"surahContentArabic"]];
NSLog(@"surahID = %@, surahName = %@",strID, strName);
[surahId addObject:strID];
[surahContentArabic addObject:strName];
}
[self.tblView reloadData];
[database close];
}
Any solution?? Thanks
任何解决方案谢谢
1 个解决方案
#1
0
Try to fetch Data from DB in main Thread as following :
尝试从主线程中的DB获取数据,如下所示:
dispatch_async(dispatch_get_main_queue(), ^{
[self getAllData];
});
This main thread has high priority and will execute faster than ever. So try this one.
该主线程具有高优先级,并且执行速度比以往更快。试试这个吧。
Hope it helps..
希望能帮助到你..
#1
0
Try to fetch Data from DB in main Thread as following :
尝试从主线程中的DB获取数据,如下所示:
dispatch_async(dispatch_get_main_queue(), ^{
[self getAllData];
});
This main thread has high priority and will execute faster than ever. So try this one.
该主线程具有高优先级,并且执行速度比以往更快。试试这个吧。
Hope it helps..
希望能帮助到你..