Pathetic Learner
Pathetic Learner

Reputation: 729

going back to previous screen in iPhone

I am new to iPhone development, i have used view based application in which i have use navigation controller, after clicking row in custom table view, it shows a navigation controller with back button titled with the default title of previous screen.

But in detail view i have created a custom back button and after clicking on that button i want to go back to the previous screen.

code to call custom button is:

  [backBtn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];

and the code inside of btnClicked is:

  [self dismissModalViewControllerAnimated:YES];

but i am not going to the previous screen.

Upvotes: 3

Views: 6878

Answers (3)

Ravi Kumar Karunanithi
Ravi Kumar Karunanithi

Reputation: 2218

You can use this code

 [[self parentViewController] dismissModalViewControllerAnimated:YES];

Upvotes: 1

visakh7
visakh7

Reputation: 26390

If you have used a navigationController i guess you might have pushed the view onto the stack using pushViewController: animated: method. or perhaps even presentModalViewcontroller: animated:

If its the first case then in your custom back button method you should do

[self.navigationController popViewControllerAnimated:YES];

If its the second case then it should do dismissModalViewControllerAnimated: but remember to dismiss from the object used to present it.

Upvotes: 11

Wolverine
Wolverine

Reputation: 4329

Use This:

    [self popViewControllerAnimated: YES];

And Make sure your Viewwillappear method must Be there.

Upvotes: 1

Related Questions