Domanda

I guess this is a two part question. First part is: I have a view controller where there are two Image Views, both user inter-actable. In both I call:

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
    imagePicker.delegate = self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:imagePicker animated:YES completion:nil];
}

And the delegate method handles the picked image form the photo library. But right now I have to way of choosing which Image View gets that picture unless I make a custom UIView with two buttons where the user picks the Image View. It's more clicks and not very practical. I tried making another NSObject file but it can't use [self presentViewController...]. Calling the method in a new View Controller can't present UIImagePickerController because it's not in the window hierarchy. Is there a way to differentiate inside didFinishPickingMediaWithInfo which Image View calls the picker?

And maybe this second part of the question doesn't really belong here but it still has to do with pictures. If the user selects one picture and adds it to the gallery, goes and selects another and another...lets say 10 pictures...what's the best way of doing this, I mean GCD or NSOperationQueue? Reason why I'm asking is what if the user is on a slow mobile internet connection and after loading them to either GCD or NSOpQueue they leave the view controller...will those images continue loading to the server? I know you can make an order with NSOpQueue and I guess you can cancel the operation when the viewWillDisappear...Is that the way to do it?

I know it's a log of writing and not a lot of code but trying to learn the best way to go about all this. Thanks!

È stato utile?

Soluzione

Here is my experience of what I've done in similar situations, I hope this helps.

First, regarding the initial part of your question, you have not way of reading the parameters of the method didFinishPickingMediaWithInfo to determine what UIImageView was the one pressed. But you can easily keep a reference to the lastPressedImageView in you view controller and keep it as simply as reading this variable once you receive didFinishPickingMediaWithInfo.

Regarding the second part of your question I recommend you reading / researching about AFNetworking which is a really powerful and easy to learn library for networking in iOS. You'd need to add your own logic to create the requests and send them, as well as for controlling possible errors, but this lib will help you to concentrate on logic instead of low-level networking concerns.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top