1
votes

I have embedded a UITabBarController inside a UINavigationController. The UITabBarController contains 3 different tabs which leads to 3 different UIViewControllers which displays UITableView. I implemented all these through storyboard. In the first UIViewController, I have implemented a UISearchController for the UITableView programatically which is working. The View turns black when I search for a particular cell and then if I switch tabs. I believe that the issue has some relation to SearchController because before including the SearchController, I didn't have any issues.

I have gone through few other questions in here, but none could solve my issue.

Edited :

Below is my code related to SearchController.

@interface

@property (nonatomic, strong) UISearchController *searchController;
@property BOOL searchControllerWasActive;
@property BOOL searchControllerSearchFieldWasFirstResponder;

@implementation

viewDidAppear()

self.searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
[self.searchController.searchBar sizeToFit];
self.tblContactsTable.tableHeaderView = self.searchController.searchBar;

self.searchController.delegate = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.delegate = self;

self.definesPresentationContext = YES;

- (void)updateSearchResultsForSearchController:(UISearchController *)searchController

//reloads table view according to what is searched.

-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar

self.searchController.searchBar.showsCancelButton = NO;
3
please share your codeAbhinandan Pratap
sample code of which part should i share ?Sachin Dinesh
please apply the below code i answer to your question. i also faced the same problem of black screenAbhinandan Pratap
I created the UITabBarController using StoryBoard and its working without the SearchController.Sachin Dinesh

3 Answers

1
votes

UITabBarController should be the top most element on window from your storyboard/code and you can add the Navigation Controllers and View Controllers to UITabBarController view controllers. https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UITabBarController_Class/index.html

1
votes

use this sample code it will surely help you here chatlist, contactlist and findfriends are 3 UIViewControllers

- (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
    //    self.navigationItem.hidesBackButton=YES;

        self.navigationController.navigationBar.backgroundColor = [UIColor blueColor];

        _chatlist = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ChatListVC"];
        _contactlist = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListVc"];
        _findfriends = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"FindfriendsVC"];

        self.tabbarcontroller = [[UITabBarController alloc]init];

        self.viewControllers = [NSArray arrayWithObjects:_chatlist,_contactlist,_findfriends, nil];


        self.tabBar.frame =CGRectMake(0,44,self.view.frame.size.width,50);

        UITabBarItem *item0 = [self.tabBar.items objectAtIndex:0];
        UITabBarItem *item1 = [self.tabBar.items objectAtIndex:1];
        UITabBarItem *item2 = [self.tabBar.items objectAtIndex:2];

        item0.title = @"Chat List";
        item1.title = @"Contacts";
        item2.title = @"Find Friends";

        [item0 setFinishedSelectedImage:[UIImage imageNamed:@"chatlist.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"chatlist.png"]];
        [item1 setFinishedSelectedImage:[UIImage imageNamed:@"contacts.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"contacts.png"]];
        [item2 setFinishedSelectedImage:[UIImage imageNamed:@"findfriends.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"findfriends.png"]];


    }
0
votes

Figured out the answer myself. I don't know if its the exact right way of doing it but now the App seems working.

I place my UITabBarController as the Initial View and separate UINavigationControllers for each tabs.