How do I dismiss the camera and go to the root view controller?

I have created 3 views. The first is the view of the house, the second is the inventory, and the third is the view from above. Now from the main screen using pushviewcontroller I go to the inventory view screen. In the inventory view, I have one grab button. the capture button will open the camera to overlayview. Now the problem is that there is a button on the overlay called the back button, when I press this button I want to go to the main screen, but for that I need to poll the camera 1st. How is this possible?

Grab button in inventory view

   -(IBAction) btnCapture:(id) sender
   {
     @try 
     {
          [self showImagePicker:UIImagePickerControllerSourceTypeCamera]; 
     }
      @catch (NSException *exception) 
      {
         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Camera" message:@"Camera is not available  " delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
         [alert show];
         [alert release];
      }
}

      

In the OverlayView Back window:

    -(IBAction)btnBack:(id)sender
     {
          app.navcntr=1;
          [self.delegate didFinishWithCamera];
          [self dismissModalViewControllerAnimated:YES];
      }

      

and in the inventory view viewWillAppear

   -(void) viewWillAppear:(BOOL)animated
    {
          if(app.navcntr ==1)
          {
                [self.navigationController popToRootViewControllerAnimated:YES];
          }
           app.navcntr=0;
   }

      

The problem is it is going to the home screen, but the app crashed. How to solve it?

Thank. enter image description here

+3


source to share


2 answers


I think you are trying to reject the camera view twice. I mean the method will didFinishWithCamera

reject it. Delete the line[self dismissModalViewControllerAnimated:YES];

-(IBAction)btnBack:(id)sender
     {
          app.navcntr=1;
          [self.delegate didFinishWithCamera];              
     }

      

EDITED



You do not have to animate when you are not on the screen ("appears").

Write your code in viewDidAppear

like

-(void) viewDidAppear:(BOOL)animated
    {
          [super viewDidAppear:animated];

          if(app.navcntr ==1)
          {
                [self.navigationController popToRootViewControllerAnimated:YES];
          }
           app.navcntr=0;
   }

      

+2


source


You will need to reject the modal view controller from the controller that owns the UIImagePickerController.

-(IBAction)whilePoppingBack:(id)sender{
    [controllerWhichContainsPicker dismissModalViewControllerAnimated:YES];
}

      

// Once that's done, you can happily navigate to your homeview controller using the popToRootViewController method.



PS Note: looking for the controller WhichContainsPicker is another thing that depends on the view hierarchy you created based on the fact that you need to dismiss this early on later. You need to do other things like navigation and other views.

// Another thing that I suspect is a memory leak (as you mentioned here: wait_fences: failed to get response: 10004003 ). Try running the tools tool or NSZombie or NSMallocGaurd to enable and try to figure out the location of the leak if the above code doesn't seem to solve the problem.

Let me know if you can get rid of it!

0


source







All Articles