The exact context is :
- View 1 call web service to get array of data.
- Then View 1 call masterDb to insert that array of data. In every loop, the current index is passed back to View 1 for updating UIProgressView progress. But currently, I tried many different ways but no one worked.
These are the code:
View 1:
- (void)onClientFinish:(NSString *)clientid status:(NSString *)status mesg:(NSString *)mesg action:(NSString *)action data:(NSObject *)data {
NSArray *dataArray = (NSArray*)data;
[self performSelectorInBackground:@selector(backgroundProcess:) withObject:dataArray];
}
(void) backgroundProcess:(NSArray *)dataArray {
BOOL result = [m_dbMaster updateMasterData:dataArray];
if(!result)
[utilClass showMessage:[NSString stringWithFormat:@"Download Master data fail."]];
else
[utilClass showMessage:[NSString stringWithFormat:@"Download Master data successfully."]];
[m_dbMaster closeDb];
[self endDownload]; }
- (void) onConfirm:(NSArray *)entryList {
int dataLength = [[entryList objectAtIndex:0] intValue];
int currentIndex= [[entryList objectAtIndex:1] intValue];
float progress = (float)currentIndex / (float)dataLength ;
[self performSelectorOnMainThread:@selector(updateProgress:)
withObject:[NSNumber numberWithFloat:progress]
waitUntilDone:NO];
}
Master DB
- (BOOL) updateEmpArr:(NSArray*) dataArray {
//delete all and add later
sqlite3_exec(m_db, "BEGIN EXCLUSIVE TRANSACTION", 0, 0, 0);
.......
char *errMesg ;
NSString *insertSql = @"INSERT INTO EMPLOYEE(EMP_ID, EMP_CODE, EMP_NAME, EMP_OUTLET, EMP_DEPT) VALUES ";
int index = 0;
for (NSMutableDictionary *empData in dataArray) {
NSArray *entrys = [[NSArray alloc] initWithObjects:[NSString stringWithFormat:@"%lu", (unsigned long)[dataArray count]],[NSString stringWithFormat: @"%d",index+1], nil];
[self.delegate onConfirm:entrys];
......
index ++;
}
return result ;
}
Please help me. Really appreciate for all helps.
Aucun commentaire:
Enregistrer un commentaire