我有一個視圖控制器,加載一些數組。當一切正在加載時,我需要提供另一個視圖控制器(使用UIProgressView
)並更新它的UI(UIProgressView
的progress屬性),然後解散並顯示下載的數據。我真的很努力,我已經嘗試過代表團,但沒有爲我工作。更新視圖控制器的用戶界面,然後解僱它
- (void)viewDidLoad
{
[super viewDidLoad];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"downloaded"]) {
} else {
NSLog(@"First time Launched");
ProgressIndicatorViewController *progressVC = [ProgressIndicatorViewController new];
progressVC.modalPresentationStyle = UIModalPresentationFullScreen;
[self syncContacts];
[self presentViewController:progressVC animated:YES completion:nil];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"downloaded"];
[progressVC release];
}
}
同步觸點方法:
- (void)syncContacts
{
NSLog(@"Sync data");
NSMutableArray *allContacts = [ContactsOperations getAllContactsFromAddressBook];
NSInteger allContactsCount = [allContacts count];
if (allContactsCount > 0) {
for (ContactData *contact in allContacts) {
NSMutableArray *phoneNumbersArray = [[NSMutableArray alloc] init];
NSString *nospacestring = nil;
for (UserTelephone *tel in [contact.abonNumbers retain]) {
NSArray *words = [tel.phoneNumber componentsSeparatedByCharactersInSet :[NSCharacterSet whitespaceCharacterSet]];
NSString *nospacestring = [words componentsJoinedByString:@""];
[phoneNumbersArray addObject:nospacestring];
}
contact.abonNumbers = phoneNumbersArray;
if (phoneNumbersArray != nil) {
NSLog(@"NOT NULL PHONENUMBERS: %@", phoneNumbersArray);
}
NSDictionary *dataDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:contact.abonNumbers, @"phoneNumbers", contact.contactName, @"fullName", [NSNumber numberWithBool:contact.isBlackList], @"blacklist", [NSNumber numberWithBool:contact.isIgnore], @"ignore", contact.status, @"status", nil];
NSLog(@"dictionary: %@", dataDictionary);
NSError *error;
NSData *postData = [NSJSONSerialization dataWithJSONObject:dataDictionary options:0 error:&error];
NSLog(@"POST DATA IS : %@", postData);
NSMutableURLRequest *newRequest = [self generateRequest:[[NSString stringWithFormat:@"%@c/contacts%@%@", AVATATOR_ADDR, SESSION_PART, [[ServiceWorker sharedInstance] SessionID]] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding] withHTTPMethod:@"POST"];
[newRequest setHTTPBody:postData];
[newRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
//__block NSMutableData *newData;
[NSURLConnection sendAsynchronousRequest:newRequest queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
if (!connectionError) {
NSDictionary *allData = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"alldata from contacts: %@", allData);
//NSInteger errorCode = [[allData objectForKey:@"CommandRes"] integerValue];
//if (errorCode == 0) {
NSInteger remoteId = [[allData objectForKey:@"contactId"] integerValue];
contact.remoteId = remoteId;
NSLog(@"remote id is from parse content : %d", remoteId);
[[AvatatorDBManager getSharedDBManager]createContactWithContactData:contact];
} else {
NSLog(@"error");
}
}];
//Somewhere here I need to update the UI in another VC
[phoneNumbersArray release];
[dataDictionary release];
}
} else {
}
}
生成請求方法:
- (NSMutableURLRequest *)generateRequest:(NSString *)urlString withHTTPMethod:(NSString *)httpMethod
{
NSLog(@"url is :%@", urlString);
NSURL *url = [NSURL URLWithString:urlString];
request = [NSMutableURLRequest requestWithURL:url];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[request setHTTPMethod:httpMethod];
return request;
}
ProgressViewController只是一個空VC與進度條。還沒有代碼。
您的代碼在哪裏? – Raptor
那麼你的問題是什麼?你想從代碼中得到什麼?現在產生了什麼?有希望地用截圖指定。 – Bourne
需要在單獨的視圖控制器中顯示進度條,還是需要以最有效的方式顯示進度欄?你是否簡單地假設它必須顯示在一個單獨的視圖控制器中? –