3

I've added the ELCimagepicker (https://github.com/Fingertips/ELCImagePickerController) to my project and it works perfectly, allowing the user to select multiple images for a slideshow. But when you click 'Save', there can be a lengthy delay depending on how many photos were added.

I've been trying to add a UIActivityIndicator when the user clicks 'Save', but having trouble due to the modal view that is presented. I can call a method from the activity that ELCimagepicker presents (ELCImagePickerController) and this gets actioned by the activity handling the presenting of the image picker. But whenever I try to add to the view, it isn't shown as the modal is on top of the activity indicator.

I've tried using bringSubviewToFront, I've tried adding the code directly to the imagepicker method file with [[self parentViewController] addSubView], but no luck.

Here's the latest code I tried: (indicator is declared in the .h file as UIActivityIndicator *indicator)

 indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.hidden=false;

[self.navigationController.view addSubview:self.indicator];
[self.navigationController.view bringSubviewToFront:self.indicator];

[indicator startAnimating];

if([delegate respondsToSelector:@selector(elcImagePickerController:showIndicator:)]) {
    [delegate performSelector:@selector(elcImagePickerController:showIndicator:) withObject:self withObject:@"test"];
}

Has anyone had any success with adding a UIActivityIndicator on top of the ELCimagepicker, or another modal view handled by another class?

I've tried MBProgressHUD but couldn't get that working quite right either - it would show up when I used it in the ELCimagepicker class, but crashed on removal with:

bool _WebTryThreadLock(bool), 0x42368e0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...

Any help would be fantastic.

Thanks.

wickets
  • 89
  • 2
  • 11
  • Are you able to post up the working code? – Matthew Lanham Jul 03 '11 at 09:17
  • 1
    @toddl can you plz post your working code or guidance as I am facing similar problem for putting indicator. and I am also not much familiar with performSelectorOnMainThread and how to get it working. – Janak Nirmal Nov 21 '11 at 10:41
  • @toddl Hi can you plz post helpful code. how did you resolved as I am still not able to resolve. any guidelines plz ? – Janak Nirmal Nov 22 '11 at 13:17

3 Answers3

4

I have figure out your problem. You can do this as below..

-(void)selectedAssets:(NSArray*)_assets {

UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
UIViewController * topView = [self.viewControllers objectAtIndex:[self.viewControllers count]-1];
activityIndicator.center = CGPointMake(topView.view.frame.size.width/2, topView.view.frame.size.height/2);
[activityIndicator setHidden:NO];
[topView.view addSubview:activityIndicator];
[topView.view bringSubviewToFront:activityIndicator];
[activityIndicator startAnimating];

[self performSelector:@selector(doProcess:) withObject:_assets afterDelay:2.1];

}

- (void) doProcess:(NSArray *)_assets {

NSMutableArray *returnArray = [[[NSMutableArray alloc] init] autorelease];

for(ALAsset *asset in _assets) {

    NSMutableDictionary *workingDictionary = [[NSMutableDictionary alloc] init];
    [workingDictionary setObject:[asset valueForProperty:ALAssetPropertyType] forKey:@"UIImagePickerControllerMediaType"];
    [workingDictionary setObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]] forKey:@"UIImagePickerControllerOriginalImage"];
    [workingDictionary setObject:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]] forKey:@"UIImagePickerControllerReferenceURL"];

    [returnArray addObject:workingDictionary];

    [workingDictionary release];    
}

[self popToRootViewControllerAnimated:NO];
[[self parentViewController] dismissModalViewControllerAnimated:YES];

if([delegate respondsToSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:)]) {
    [delegate performSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:) withObject:self withObject:[NSArray arrayWithArray:returnArray]];
}

}

Let me know if this answer help you ...

Thanks, MinuMaster

MinuMaster
  • 1,457
  • 1
  • 13
  • 29
1

It looks like you are updating UI on a background thread. All UIKit updates are to be done in the main thread. So I recommend you execute methods doing UI updates using performSelectorOnMainThread:withObject:.

Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
  • Thanks - I've now implemented the call back to the main class as [delegate performSelectorOnMainThread:@selector(elcImagePickerController:) withObject:self waitUntilDone:YES]; This gets called on my main class and does display the activityindicator - but only AFTER the modal view has finished. I think I might be adding it to the view incorrectly - I tried [self.view addSubview:activityIndicator], that only showed afterwards, so I tried things like self.navigationController.view, and the visibleViewController, topViewController etc... How do I tell it to be 'on top' of the modal view? – wickets May 28 '11 at 10:58
  • You can store a reference to the modal view controller and add the `activityIndicator` to its subview when the delegate method is called or otherwise you can use notifications. – Deepak Danduprolu May 28 '11 at 11:15
  • The modal view controller is called elcPicker and I do this when it is called back in the main class, from the imagepicker class with performSelectorOnMainThread, with [elcPicker.view addSubview:activityIndicator], but this is when it doesn't appear. – wickets May 28 '11 at 12:02
  • Thanks - I've got it working now with a combination of performSelectorOnMainThread and changing the elcImagePicker classes to performSelectorOnBackgroundThread. – wickets May 29 '11 at 00:23
  • 1
    @toddl can you plz post your working code or guidance as I am facing similar problem for putting indicator. and I am also not much familiar with performSelectorOnMainThread and how to get it working. – Janak Nirmal Nov 21 '11 at 09:51
  • @toddl Hi can you plz post helpful code. how did you resolved as I am still not able to resolve. any guidelines plz ? – Janak Nirmal Nov 22 '11 at 13:18
  • @Jennis If you are having a issue which is probably similar to this, you should open a new question explaining your problem in detail and should include a link to this question if you deem necessary. – Deepak Danduprolu Nov 22 '11 at 15:22
0

I solved the issue like this

     activityIndicatorObject = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

     // Set Center Position for ActivityIndicator

     activityIndicatorObject.center = CGPointMake(150, 250);
     activityIndicatorObject.backgroundColor=[UIColor grayColor];

     // Add ActivityIndicator to your view
     [self.view addSubview:activityIndicatorObject];

     activityIndicatorObject.hidesWhenStopped=NO;

     [activityIndicatorObject startAnimating];