2
votes

I have a iPhone app in which need to add UISearchbar on navigation bar, so that user can search from any where inside the app. When User Searches it displays search result in a Tableview controller and User can select any row which pushes to other controller.

Below is the Structure which i have in StoryBoard

  • Navigation Controller
    • Tab Bar Controller
      • View Controller1
      • View Controller2
      • View Controller3
      • View Controller4

Attached Story Board Screenshot

I can successfully add the UIsearchbar on Navigationbar in ViewController 1

 UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage      imageNamed:SEARCH]];
imageView.frame = CGRectMake(0, 0, 20, 20);

UITapGestureRecognizer *tapGesture =
[[UITapGestureRecognizer alloc] initWithTarget:self
                                        action:@selector(searchTapped:)];
[imageView addGestureRecognizer:tapGesture];

self.searchButton = [[UIBarButtonItem alloc] initWithCustomView:imageView];
self.searchButton.style = UIBarButtonItemStylePlain;
 self.searchButton.target = self;
 [self.searchButton setTintColor:[UIColor whiteColor]];
self.tabBarController.navigationItem.rightBarButtonItem = self.searchButton;

I can successfully implement the Search results as well in Tableview controller but when user select row it Pushes to different controller. Below is the code which implmenetd to push to different controller.

 UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"  bundle: nil];
    EntityViewController *entityController = [mainStoryboard  instantiateViewControllerWithIdentifier:ENTITYIDENTIFIER];
    entityController.dataDic = result;
     [self.navigationController pushViewController:entityController  animated:YES];

The problem here is when it pushes to different controller the TabBar is completely hidden and Navigation bar right button is completely Hidden.

I tried to Unhide the tab bar and Navigation bar but no effect. I tried all possibilities but nothing worked.

Can some one please let me know what is right approach to solve this issue.

Thanks In Advance.

2
Chonch is right, this answer is what works, you have to change your set upLarry Pickles
added my comment to Chonch answer.Kishore
Added my comments to your comment... :-)Rony Rozen

2 Answers

3
votes

Have you tried switching the order of the UINavigationController and the UITabController?

Right now, it seems like you have a UINavigationController with a UITabController "inside" it. So, when you push something else to the UINavigationController, the UITabController is being pushed aside, as it is no longer relevant.

If you were to have the UITabController on the top most level, with the UINavigationController at each of the tabs (or only on the relevant ones), when you'll push another view controller to that UINavigationController, it won't affect the tab bar, since it will still be on the top most level, completely unaffected by the push.

I hope this helps. Good Luck!

1
votes

Thanks for the help. I resolved the issue by making Tab Bar controller as TOP View and Navigation controller for each view ( as per requirement. I made SearchController separately so that user can search from any where inside the app.

Current Implementation

I updated this as it can be help full for those who needs to implement similar kind of requirement.

If there is a better approach of implementation please do provide your comments.

Thanks