次のコードは、Parse.comの配列をループしてローカルデータストアからサーバーにアップロードします。もちろんここでの問題は、成功したエントリごとにUIAlertViewを作成することです...これは非常に厄介なものになります。エラーがなければ表示されるが、ループの最後には1回だけ行うように変更するにはどうすればよいですか?Forループの終了時にUIAlertViewを表示...エラーがない場合
-(void)uploadToParse {
int i;
for (i = 0; i < [self.objects count]; i++) {
PFObject *entry = [self.objects objectAtIndex:i];
NSString *imageFileName = [entry[@"FamilyName"] stringByAppendingString:@".png"];
NSLog(@"%@", imageFileName);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:imageFileName];
UIImage *newImage = [UIImage imageWithContentsOfFile:filePath];
NSData* data = UIImagePNGRepresentation(newImage);
PFFile *imageFile = [PFFile fileWithName:@"Locationimage.png" data:data];
[entry setObject:imageFile forKey:@"HousePicture"];
[entry saveInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
if (!error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Upload Complete" message:@"Successfully added your Bible Distribution data." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[entry unpinInBackgroundWithName:@"Share" block:^(BOOL succeeded, NSError * _Nullable error) {
}];
}
}];
[entry unpinInBackgroundWithName:@"Share" block:^(BOOL succeeded, NSError * _Nullable error) {
[self loadObjects];
}];
}
}
完璧、まさに私が必要としていたものです。 – user717452