I have few hundredths of rows in my few tables. If I read these rows from main thread UI goes unresponsive.
I want to read these rows in some other thread so that my UI thread wont get stuck
(seems in iOS it is related to dispatch queue kind of thing, dont know very much)
I have written few code based on my understanding but my application is getting crash.
// This is my .h file
I want to read these rows in some other thread so that my UI thread wont get stuck
(seems in iOS it is related to dispatch queue kind of thing, dont know very much)
I have written few code based on my understanding but my application is getting crash.
// This is my .h file
Code:
@interface HistoryViewController : UIViewController
{
NSArray *data1;
NSArray *data2;
NSArray *data3;
}
@property (nonatomic, retain) NSArray *data1;
@property (nonatomic, retain) NSArray *data2;
@property (nonatomic, retain) NSArray *data3;
Code:
// This is my .m file
@synthesize data1, data2, data3;
- (void)readLocalDBData
{
// start the activity indicator
[self.view addSubview:fadeView];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
DebugLog(@"STARTED LONG RUNNING TASK FROM HERE... ");
_data1 = [GetAppDelegate().databaseWrapper getDataFromTable1]; // returns nil in case of zero rows
_data2 = [GetAppDelegate().databaseWrapper getDataFromTable2]; // returns nil in case of zero rows
_data3 = [GetAppDelegate().databaseWrapper getDataFromTable3]; // returns nil in case of zero rows
dispatch_async(dispatch_get_main_queue(), ^{
DebugLog(@"FINISHED MY LONG RUNNING TASK...");
// stop activity indicator
[self.fadeView removeFromSuperview];
// update ui method called
[self updateUI];
});
});
}
- (void)updateUI
{
if (data1 == nil)
{
[self.fadeView removeFromSuperview];
return;
}
[COLOR="Red"][B] // in this line I am getting crash with EXE_BAD_ACCESS
DebugLog(@"History Items %@", [data1 count]);[/B][/COLOR]
DebugLog(@"NEWS History Items %d", [data2 count]);
DebugLog(@"PRODUCT History Items %d", [data3 count]);
}