Search code examples
iosobjective-ciphoneuitableviewpresentviewcontroller

after dismissing View one subview hast different place


Hello I have a problem with un/showing a TableViewController.

I have a Scrollview with 4Subviews (the last subView is optionally, if a Button is clicked or not). In this optionally subview is a Button. If the button is clicked a new View with a TableView will open. If i click a cell in this TableView i want to go back to the last View.

Everything works fine, but the optionally View is shown always in the middle of the Screen instead of the last View on the ScrollView.

function to show the TableView:

- (void)CategoryButtonClicked:(id)sender {
[self presentViewController:advancedSearchTableViewController animated:YES completion:nil];
advancedSearchTableViewController.SourceView = @"Category";}

function to dismiss the Table View:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

[self dismissViewControllerAnimated:YES completion:nil];}

Solution

  • Use the Container View pattern and add your tableViewController as a child view controller. Here is a good reference: https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html