Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-02-2010, 12:10 PM   #1 (permalink)
Registered Member
 
Kilby's Avatar
 
Join Date: Nov 2009
Location: Baltimore, MD
Posts: 13
Kilby is on a distinguished road
Arrow dismissModalViewController not working as expected

Hello All,

I have a problem that I'm helping someone can shed some light on. I'm sure it is something very simple, but I just can't see it and could really use an extra set of eyes to help find this bug.

The app I'm working on uses UIImagePickerController to present a camera preview with the stock camera UI hidden. This preview implements a cameraOverlay view with a few buttons to perform my required tasks, one of which is to dismiss the camera preview.

For some reason, the function to dismiss the camera view will not work when being called by the button in the overlay view. I can NSLog the function and see that it is in fact being called by the button, but simply doesn't allow the dismissModalViewController to work. I have tested the function by having an NSTimer call it a few seconds after it loads, and it works fine, just not when I call it from the button in the cameraOverlay.

My viewController (CameraTestViewController.m) calls the UIImagePicker as shown below with the press of a button.

Code:
-(IBAction) getPhoto:(id) sender {
	
	
	OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];
	picker = [[UIImagePickerController alloc] init];
	picker.delegate = self;
	picker.sourceType = UIImagePickerControllerSourceTypeCamera;
	picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
	picker.cameraOverlayView = overlay;
	picker.showsCameraControls = NO;
	picker.toolbarHidden = YES;
	[self presentModalViewController:picker animated:NO];
	//[self performSelector:@selector(doCancel) withObject:nil afterDelay:10];

}
I dismiss the camera view with this method elsewhere in the viewController

Code:
-(void)doCancel
{	
	NSLog (@"doCancel method has been called");
	[picker dismissModalViewControllerAnimated:YES];
}
Then in my OverlayView.m class, I set up the required buttons and provide a method that calls the dismissing of the modal view controller.

Code:
- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
		// Clear the background of the overlay:
		self.opaque = NO;
		self.backgroundColor = [UIColor clearColor];

                  ...

myButton04 = [UIButton buttonWithType:UIButtonTypeCustom];
		myButton04.frame = CGRectMake(10, 447, 44, 13);
		[myButton04 setTitle:@"" forState:UIControlStateNormal];
		[myButton04 addTarget:self action:@selector(scanButton05TouchUpInside) forControlEvents:UIControlEventTouchUpInside];
		[myButton04 setImage:[UIImage imageNamed:@"camControlsBack.png"] forState:UIControlStateNormal];
		[self addSubview:myButton04];

                  ...

    }
	
    return self;
	
}


- (void) scanButton05TouchUpInside {

	NSLog(@"BACK BUTTON HAS BEEN PRESSED");
	CameraTestViewController *baseViewController = [[CameraTestViewController alloc] init];
	[baseViewController doCancel];

}
ANY help on this would be most appreciated. I'm sick of having a purple forehead from beating my head against the wall over this one.

THANKS!
Kilby is offline   Reply With Quote
Old 07-02-2010, 02:30 PM   #2 (permalink)
Registered Member
 
Kilby's Avatar
 
Join Date: Nov 2009
Location: Baltimore, MD
Posts: 13
Kilby is on a distinguished road
Default

Any Ideas anyone?

Why would my 'doCanel' method work while being called from an NSTimer for testing purposes, but not when I press the button in the OverlayView?
Kilby is offline   Reply With Quote
Old 07-08-2010, 04:52 PM   #3 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 37
Smokin Joe is on a distinguished road
Default

I think you may need to access your parentViewController (the ViewController that is setting up your overlayViewController) through your application Delegate.

I was having an issue where a parentViewController would alloc and add a childViewController to the superview. However, there were some interactions within the childViewController that I wanted to trigger actions in my parentViewController. To do this, within my childViewController:

Code:
	ProjectAppDelegate *appDelegate = (ProjectAppDelegate *)[[UIApplication sharedApplication]delegate];
	ParentViewController *pvc = appDelegate.viewController;
	[pvc methodInParentViewController];
With the above code, I assume that the *viewController object exists and is your ParentViewController.

Essentially, if you have to traverse BACK through layers of ViewControllers, I'd suggest using the ApplicationDelegate.
Smokin Joe is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 329
5 members and 324 guests
anothermine, Chickenrig, givensur, michaelhansen, PixelInteractive
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:26 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0