切换标签时,UITabBarController变为黑色

时间:2016-03-14 05:41:54

标签: ios objective-c uinavigationcontroller uitabbarcontroller uisearchcontroller

我在UINavigationController中嵌入了 UITabBarController UITabBarController 包含3个不同的标签,这些标签可显示3个不同的 UIViewControllers ,显示UITableView。我通过故事板实现了所有这些。在第一个UIViewController中,我已经以编程方式为UITableView实现了一个 UISearchController 当我搜索特定单元格时,视图变为黑色,然后我切换标签。 我相信这个问题与SearchController有一些关系,因为在包含SearchController之前,我没有任何问题。

我在这里已经解决了其他一些问题,但没有一个能解决我的问题。

编辑:

以下是与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 个答案:

答案 0 :(得分:1)

使用此示例代码,它肯定会帮助您在这里聊天列表,联系人列表和查找朋友是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"]];


    }

答案 1 :(得分:1)

UITabBarController 应该是故事板/代码中窗口中最重要的元素,您可以将导航控制器和视图控制器添加到UITabBarController视图控制器。 https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UITabBarController_Class/index.html

答案 2 :(得分:0)

自己想出答案。我不知道它是否是正确的做法,但现在应用程序似乎正在运作。

我将UITabBarController作为初始视图放置,并为每个标签分隔UINavigationControllers。