views:

150

answers:

3

Hello!

I have a NavBar, a TabBar and a SearchBar with a ScopeBar. So the user can perform a search via a remote server. Clicking on one TableRow of the TableView a new ViewController with a xib is pushed into.

It is doing some calculations and it is possible, that I have to dismiss this View(Controller) and I should go back like I am clicking the "back" button in the NavBar.

How could I do this programmatically and call a method in this ViewController, because I have to trigger the search with the saved search term.

Does anyone know this?

Thanks a lot in advance & Best Regards.

+1  A: 
- (UIViewController *)popViewControllerAnimated:(BOOL)animated

if you are

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
CiNN
I use this:[self.myNavigationController popViewControllerAnimated:YES];And it works. But how could I trigger a search? Either I have to simulate a click on the "search" button of the keyboard or I have to call a method which "re-search".Or I have to delete this special TableRow from which I "came back".
Tim
A: 

Use delegation. Have the table view controller create your new view controller newViewController and set newViewController.delegate = self before pushing it onto the navigation stack.

Then in newViewController, just before you popViewControllerAnimated: call some method like [delegate doWhateverWhenNewViewControllerIsPopped: ...]. Ideally you declare a protocol called something like NewViewControllerDelegate and have the controller above implement it.

You can change the back button of NewViewController to something like "Done" or whatever by changing it's left navigation button. (See the properties of UIViewController.)

Hope that makes sense.

Nimrod
Hm, I have TestDetailViewController *testDetailViewController = [[TestDetailViewController alloc] initWithNibName:@"TestDetailView" bundle:[NSBundle mainBundle]]; testDetailViewController.title = testClass.name; testDetailViewController.userKey = testClass.keyId; testDetailViewController.delegate = self;The line with the delegate display the error:Request for member 'delegate' in something not a structure or union.
Tim
There's no delegate property by default. Make sure you declare a property for delegate in TestDetailViewController. Ideally it should be of type "id <TestDetailViewDelegate>" so that any object that implements the TestDetailViewDelegae protocol can be assigned to delegate. The protocol can just contain one method like testDetailViewControllerDone: ...
Nimrod
I have this in my declaration:<MKMapViewDelegate,MKReverseGeocoderDelegate> so I thought it must be okay. Because this source code worked standalone. I integrated in an existing project and now it does not work anymore.
Tim
I solved it: It was the wrong connected view! I connect it to the View instead of the Map.Thanks a lot for your help!
Tim
A: 

I solved the problem, take a look at the comments.

Tim