标签: uisearchcontroller

Swift UISearchController连接在Core Data Project中,app运行,但搜索不更新

过去几天我一直在为TableViewController使用Core Data 的Swift项目创建一个过滤器而摔跤.我终于想通了我需要使用a UISearchController,创建一个NSPredicatefor searchController.searchBar等.

我发现这篇文章非常有帮助,但在我对TVC这个项目进行建模之后,我发现"所有的灯都亮着,但没有人在家".我可以搜索,创建谓词searchBar,添加,删除等,但单元格不会更新以进行搜索.我错过了什么,但我不知道是什么.

以下是我的代码的相关部分.

class MasterViewController: UITableViewController, NSFetchedResultsControllerDelegate, UISearchControllerDelegate, UISearchResultsUpdating

// Properties that get instantiated later

var detailViewController: DetailViewController? = nil
var addNoteViewController:AddNoteViewController? = nil  // I added this
var managedObjectContext: NSManagedObjectContext? = nil

// Added variable for UISearchController
var searchController: UISearchController!
var searchPredicate: NSPredicate? // I added this. It's optional on and gets set later

    override func viewDidLoad() {
        super.viewDidLoad()

        self.navigationItem.leftBarButtonItem = self.editButtonItem()

        if …
Run Code Online (Sandbox Code Playgroud)

filtering core-data uisearchresultscontroller swift uisearchcontroller

8
推荐指数
1
解决办法
4050
查看次数

UISearchController在点击取消按钮时解除VC

所以,我目前正在尝试用UISearchController替换我的一个项目中的depricated searchDisplayController,我遇到了这个问题.

如果搜索中没有结果(UITableView为空),则整个ViewController被解除.当搜索结果不为空时,不会发生这种情况.我不想说清楚我没有使用UITableViewController.相反,我有一个带有UITableView的常规VC.

这是我的一些代码:

var resultSearchController = UISearchController()
override func viewDidLoad() {
    super.viewDidLoad()
    self.resultSearchController = ({
        let controller = UISearchController(searchResultsController: nil)
        controller.searchResultsUpdater = self
        controller.dimsBackgroundDuringPresentation = false
        controller.searchBar.sizeToFit()
        controller.delegate = self
        controller.searchBar.delegate = self
        self.studentTable.tableHeaderView = controller.searchBar
        return controller
    })()
    ....
}
Run Code Online (Sandbox Code Playgroud)

现在,如果我将此函数添加到等式中,则取消按钮始终会取消VC.

func searchBarCancelButtonClicked(searchBar: UISearchBar) {
    resultSearchController.active = false
}
Run Code Online (Sandbox Code Playgroud)

那么为什么要设置searchController.active = false解雇VC呢?是因为它使用与VC相同的UITableView吗?我相信旧的searchDisplayController只会显示一个正在使用的UITableView.如果是这种情况有没有办法覆盖dismissVC?

uitableview uisearchbar ios swift uisearchcontroller

8
推荐指数
1
解决办法
1300
查看次数

加载UISearchController时自动显示键盘

我在表视图控制器中创建了一个UISearchController.我使用来自另一个视图控制器的push segue来查看此表视图控制器.我希望一旦按下表视图控制器,键盘就会在搜索栏中显示光标.

我在viewDidLoad方法中使用了搜索控制器

self.mySearchController.active = true
Run Code Online (Sandbox Code Playgroud)

它确实使搜索控制器处于活动状态,但这不会调出键盘,光标也不会放在搜索栏中.我也试过了

self.mySearchController.searchBar.becomeFirstResponder()
Run Code Online (Sandbox Code Playgroud)

这条线似乎没有任何效果.

如何自动/以编程方式调出键盘?下面是我的代码的更详细版本

class PickAddressViewController: UITableViewController, UISearchResultsUpdating {

var searchText = ""

var mySearchController = UISearchController()

override func viewDidLoad() {
    super.viewDidLoad()

    self.mySearchController = ({
        let controller = UISearchController(searchResultsController: nil)
        controller.searchResultsUpdater = self
        controller.dimsBackgroundDuringPresentation = false
        controller.searchBar.sizeToFit()
        controller.searchBar.text = self.searchText

        self.tableView.tableHeaderView = controller.searchBar

        return controller
    })()

    self.mySearchController.active = true
    self.mySearchController.searchBar.becomeFirstResponder()
}
Run Code Online (Sandbox Code Playgroud)

ios swift uisearchcontroller

8
推荐指数
2
解决办法
9131
查看次数

使UISearchController搜索栏自动激活

我已经在navigatiom栏中实现了一个带有搜索栏的UISearchController,我想在加载视图时使搜索栏处于活动状态.当我说活动时,我的意思是键盘出现,用户可以在不点击搜索栏的情况下输入他/她的搜索.

我使用以下代码初始化了UISearchController:

- (void)viewDidLoad
{
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    [self.searchController setSearchResultsUpdater:self];
    [self.searchController setDimsBackgroundDuringPresentation:NO];
    [self.searchController setHidesNavigationBarDuringPresentation:NO];
    [self.navigationItem setTitleView:self.searchController.searchBar];

    [self setDefinesPresentationContext:YES];

    [self.searchController.searchBar setDelegate:self];
    [self.searchController.searchBar setShowsCancelButton:YES];
    [self.searchController.searchBar setPlaceholder:@"City or Airfield"];

    [self.searchController.searchBar sizeToFit];
}
Run Code Online (Sandbox Code Playgroud)

我试图让我的搜索控制器处于活动状态,通话[self.searchController.searchBar becomeFirstResponder]并直接呼叫,searchBarSearchButtonClicked但没有任何作用.

objective-c uisearchbar ios uisearchcontroller

8
推荐指数
2
解决办法
2万
查看次数

UITextField vs UISearchBar?

我有一个我想要搜索的集合视图.除此之外,如果用户键入了不在集合视图中的内容,我希望它继续并在数据库中搜索它.

目前我正在使用SearchController,并且我正在尝试大量定制SearchController附带的UISearchBar,如下所示:

在此输入图像描述

到目前为止我看起来像这样:

在此输入图像描述

我目前使用UISearchBar遇到的一些问题是:

  1. 在用户单击搜索字段之前,文本最初显示在左侧
  2. 将搜索字段中的文本定位为稍低
  3. 使我替换默认搜索图标的图像不会扩展到初始搜索图标的高度(这就是它看起来模糊的原因)

使用UITextField而不是SearchController对我来说更有意义,还是有办法用UITextField替换SearchController附带的UISearchBar?

uitextfield uisearchbar ios swift uisearchcontroller

8
推荐指数
1
解决办法
1272
查看次数

UISearchBar最小风格具有透明背景

UISearchBar添加到了顶部UITableView.

        // init search bar
    self.resultSearchController = ({
        let controller = UISearchController(searchResultsController: nil)
        controller.searchResultsUpdater = self
        controller.dimsBackgroundDuringPresentation = false
        controller.searchBar.sizeToFit()
        controller.searchBar.tintColor = Config.grayColor()
        controller.searchBar.searchBarStyle = UISearchBarStyle.Minimal

        self.tableView.tableHeaderView = controller.searchBar

        // set content offset for table view in order
        // that the searchbar is hidden at the beginning
        self.tableView.contentOffset = CGPoint(x: 0, y: controller.searchBar.frame.size.height)

        return controller
    })()
Run Code Online (Sandbox Code Playgroud)

这基本上看起来像预期:

在此输入图像描述

但是当我进入搜索文本域并向下滚动表视图时,它看起来很奇怪.搜索控制器的背景是透明的.

在此输入图像描述

我试着设置barTintColorbackgroundColor,但没有任何效果.

transparent uisearchbar uisearchcontroller

8
推荐指数
1
解决办法
1200
查看次数

活动时,UISearchBar与UITableView内容重叠

我有一个带有表视图和UISearchController的视图控制器.运行应用程序时,我发现搜索栏在活动时与内容重叠.当搜索栏处于活动状态时,我需要调整什么才能使内容不重叠?

普通视图:

在此输入图像描述

搜索栏处于活动状态:

在此输入图像描述

查看控制器设置:

在此输入图像描述

uinavigationbar uitableview ios swift uisearchcontroller

8
推荐指数
1
解决办法
2731
查看次数

searchController和searchResultsController问题中的StatusBar:iOS 8

嗨,这是我的问题:

在我的AppDeleagate的 didFinishLaunchingWithOptions:方法我有一个方法[self configureUINavigationControllerStlyle]; 它配置状态栏和我的应用程序的所有导航栏外观(我的UINavigationController和UITabbarController在我的应用程序中一起工作).

-(void) configureUINavigationControllerStlyle {

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;

UINavigationController *navigationController = (UINavigationController *)[tabBarController.viewControllers objectAtIndex:0];

navigationController.navigationBar.translucent = NO;

[[UINavigationBar appearance] setBarTintColor: [CustomColor getAwesomeColor:@"colorBlue3_1"]];

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

[[UINavigationBar appearance]  setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor whiteColor],
NSFontAttributeName: [UIFont fontWithName:@"AvenirNext-DemiBold" size:17.0]
 }];

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

}
Run Code Online (Sandbox Code Playgroud)

另外在我的info.plist中我设置:查看基于控制器的状态栏外观为"NO"

一切都很好,我的应用程序中的所有控制器都有蓝色背景和白色文本颜色的状态栏.但不是uisearchcontroller和uisearchresultscontroller.

我的根TableViewController看起来像这样:

https://www.dropbox.com/s/oqcozos89x9yqhg/Screen%20Shot%202014-12-11%20at%2016.21.06.jpg?dl=0

我在我的应用程序中集成了searchController和searchResultsController.逻辑运行良好,但我不明白如何处理searchController和searchResultController中的状态栏外观.他们不使用我在AppDelegate.m文件中创建的状态栏的样式.

我的searchController和searchResultsController看起来像这样(状态栏变为白色,状态栏的文本颜色也变为白色,但我需要我的状态栏与我的主视图控制器中的颜色相同(蓝色背景和白色文本颜色).

https://www.dropbox.com/s/26skdz7gvehmwl4/Screen%20Shot%202014-12-11%20at%2016.21.16.png?dl=0

另一个错误:当我使用时

navigationController.navigationBar.translucent = NO;
Run Code Online (Sandbox Code Playgroud)

在我的AppDelegate中 - 在使用搜索控制器后从详细视图控制器返回时,它会导致我的家庭桌面视图"跳跃或拉伸".当我没有设置半透明属性时 - 没有"跳跃".

也许有人知道如何在iOS 8中使用searchController时修复状态栏颜色问题.

如果我使用默认颜色(不要对我的AppDelegate添加任何更改),一切正常,但我需要在我的应用程序中自定义状态栏颜色.

uistatusbar uisearchresultscontroller appdelegate ios8 uisearchcontroller

7
推荐指数
2
解决办法
1439
查看次数

UISearchController:UITableView的Section索引与searchBar重叠

我正在构建一个使用新UISearchController的iOS 8应用程序.在与搜索控制器相关的表视图中,我使用区段索引让用户从表的一个部分快速跳转到下一个部分.它工作正常,但部分索引与表/搜索控制器上的搜索栏重叠.有没有人遇到过这个问题,如果有的话,你是怎么解决的?以下是我正在初始化搜索控制器的方法:

self.resultsTableController = [self.storyboard instantiateViewControllerWithIdentifier:[SelectSpecialtySearchResultsTVC storyboardId]];
UINavigationController *searchResultsNavController = [[UINavigationController alloc]initWithRootViewController:self.resultsTableController];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsNavController];

self.searchController.searchResultsUpdater = self;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.barTintColor = [UIColor colorWithHexString:kColorGrayLight];
self.searchController.searchBar.translucent = NO;
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, [self.view bounds].size.width, 44.0);
self.searchController.searchBar.delegate = self;

self.tableView.tableHeaderView = self.searchController.searchBar;

//present the search display controller within the confines of this class's table view
self.definesPresentationContext = YES;

// we want to be the delegate for our filtered table so didSelectRowAtIndexPath is called for both tables
self.resultsTableController.tableView.delegate = self; …
Run Code Online (Sandbox Code Playgroud)

uitableview uisearchbar ios uisearchcontroller

7
推荐指数
2
解决办法
5240
查看次数

搜索栏未显示在导航栏iOS 11上

我正在推动一个viewController,我想要一个searchBar,但搜索栏根本没有显示.下面是代码.我错过了什么吗?

var searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search here..."
definesPresentationContext = true
searchController.searchBar.delegate = self
searchController.searchBar.sizeToFit()
if #available(iOS 11.0, *) {

    self.navigationItem.searchController = searchController
} else {
    // Fallback on earlier versions
    navigationItem.titleView = searchController.searchBar
    navigationItem.titleView?.layoutSubviews()
}
Run Code Online (Sandbox Code Playgroud)

uinavigationbar ios swift uisearchcontroller ios11

7
推荐指数
1
解决办法
1876
查看次数