sankar
sankar

Reputation: 7

How to navigate previous screen from camera view in iphone?

Im new to iphone, i have custom back button in camera view and using poptoviewcontroller, its not working, but i want when i click the back button to navigate home screen, how? please any one help me.

I tried the source code

backbtn=[UIButton buttonWithType:UIButtonTypeCustom];
backbtn.frame=CGRectMake(40, 10, 80, 40);
[backbtn setBackgroundImage:[UIImage imageNamed:@"backspace.png"]            forState:UIControlStateNormal];
[backbtn addTarget:self action:@selector(gotoprevious)  forControlEvents:UIControlEventTouchUpInside];

[buttonView addSubview:backbtn];


-(void)gotoprevious
{
     NSLog(@"Go to prevoius screen");
 Homepage *homepage=[[Homepage alloc]init];
 [self.navigationController popToViewController:homepage animated:YES];

 }

Upvotes: 1

Views: 154

Answers (2)

rckoenes
rckoenes

Reputation: 69469

To remove the last add viewController from the navigation controller stack use:

[self.navigationController popViewControllerAnimated:YES];

What you are tying to do won't work because you are creating a new instance of the Homepage view controller, which is not in the stack.

popToViewController is expecting a viewcontroller instance which is already in the stack.

Upvotes: 3

beryllium
beryllium

Reputation: 29767

If I understand you correctly - you work with UIImagePickerController. So, for hiding this one and navigate to previous viewController just call dismissModalViewControllerAnimated: method

[self dismissModalViewControllerAnimated:YES];

Upvotes: 1

Related Questions