标签: uisearchcontroller

UISearchController保留问题

我正在尝试使用UISearchController但是我面临保留我无法解决的问题.MainTableview有两个部分.

第1节

过滤数据基于一些正则表达式

第2节

所有数据

我将UISearchController添加到我的tableview中,并将ResultsTableController作为resultsTableController附加.当用户搜索某些东西时,它工作,ResultsTableController出现,因为我将tableview委托设置为self,从我的MainTableViewController中的ResultsTableController调用didSelectRowAtIndexPath中选择项目.但是,如果用户从resultsTableController中选择了某些内容,则会出现分配问题.

以下是针对不同场景的

  • 用户不搜索任何内容,只需从MainTableview中选择一个项目,我就会看到deinit消息
  • 用户搜索内容,取消搜索,从MainTableview中选择项目,我看到deinit消息
  • 用户搜索某些东西,并从ResultsTableController中选择一个项目,我的视图控制器中没有得到deinit

MainTableViewController.swift

var searchController: UISearchController!

// Secondary search results table view.
var resultsTableController: ResultsTableController!
var allCompanies = ["Data1","Data2","Data3"]

override func viewDidLoad() {
    super.viewDidLoad()
     resultsTableController = ResultsTableController()
    // We want to be the delegate for our filtered table so didSelectRowAtIndexPath(_:) is called for both tables.
    resultsTableController.tableView.delegate = self
    searchController = UISearchController(searchResultsController: resultsTableController)
    searchController.searchResultsUpdater = self
    searchController.searchBar.sizeToFit()
    tableView.tableHeaderView = searchController.searchBar

    searchController.delegate = self
    searchController.dimsBackgroundDuringPresentation = false 
    searchController.searchBar.delegate = self   
    definesPresentationContext = true
    } …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift uisearchcontroller

4
推荐指数
2
解决办法
1049
查看次数

完成用户在屏幕外点击UISearchBar的动画

轻触a时UISearchBar,取消按钮滑入,TextField位于上方以容纳按钮.我将这称为取消按钮动画.

在我的应用程序中,当用户点击搜索按钮时,带有a UISearchControllerUITableView淡入的视图.我希望​​视图淡入,取消按钮动画已经完成.与iOS音乐应用类似.我试过这个:

self.myTableView.frame = CGRectMake(0, 20, self.view.bounds.width, self.view.bounds.height - 20)
self.resultSearchController.searchBar.becomeFirstResponder()

UIView.animateWithDuration(0.3, delay: 0.0, options: .CurveLinear, animations: {
    self.myTableView.alpha = CGFloat(1.0)

        }, completion: nil)
Run Code Online (Sandbox Code Playgroud)

当我将searchBar第一响应者关闭屏幕时,不应该完成取消按钮动画完成吗?它没有.

现在,取消按钮动画在屏幕上发生,然后视图(TableView)淡入.如何在视图的alpha为0时进行取消按钮动画?

animation uitableview ios swift uisearchcontroller

4
推荐指数
1
解决办法
1180
查看次数

在tvOS上禁用UISearchController上的blury背景

由于我们在整个tvOS应用程序中使用自定义背景图像,因此我需要UISearchController来模糊背景.显然,该dimsBackgroundDuringPresentation标志UISearchController在tvOS下无法使用.有没有其他方法可以摆脱它?

uisearchbar uisearchcontroller tvos

4
推荐指数
1
解决办法
948
查看次数

UISearchController searchBar在第一次单击时消失

我在TableView中实现了一个UISearchController,由一个导航控制器推送.

首先我的问题是每当我点击SearchBar时,它就会消失.当我输入一些文本时,它可以工作,但它保持完全空白.然后我设法使用此代码半解决问题:

- (void)searchForText:(NSString*)searchText
{
    [self.view addSubview:villeSearchController.searchBar];
}
Run Code Online (Sandbox Code Playgroud)

哪个半工作因为现在,当我点击搜索栏时,它会消隐,但是如果我输入一个字符,它会再次出现,然后它就会停留在那里,无论如何.直到我取消搜索,然后再次点击它,在这种情况下它会消隐.我做了一些测试,并在第一次点击时调用此方法(searchForText),因此这不是原因.

有谁知道我如何解决这个问题并让搜索栏从第一次点击出现?

编辑:

这是我初始化SearchController的方法:

villeSearchController = [[UISearchController alloc]   initWithSearchResultsController:nil];
villeSearchController.searchResultsUpdater = self;
villeSearchController.dimsBackgroundDuringPresentation = NO;
villeSearchController.searchBar.delegate = self;
villeTableView.tableHeaderView = villeSearchController.searchBar;
villeSearchController.searchBar.scopeButtonTitles = @[];
self.definesPresentationContext = YES;
[villeSearchController.searchBar sizeToFit];
Run Code Online (Sandbox Code Playgroud)

uisearchbar tableview ios uisearchcontroller

4
推荐指数
2
解决办法
6356
查看次数

警告:尝试在*上呈现View Controller,它已经呈现<UISearchController:0x142a1f7c0>

我用a UISearchController和a 做了一个视图控制器UITableView.您可以从搜索范围按钮中选择两种不同类型的搜索:组和人员.两种搜索都可以在桌面上显示并显示结果.但是,如果单击每个单元格,则应将它们定向到不同的动态页面(动态组页面或动态人员配置文件页面).用于组的工作,而用于配置文件的工作则不工作.这意味着每当我从我得到的结果中点击一个人单元格时,没有任何反应,我在控制台上打印出以下警告:

Warning: Attempt to present <MyProject.profileView: 0x13e9df000>  on <MyProject.SearchPage: 0x142a1d8f0> which is already presenting <UISearchController: 0x142a1f7c0>
Run Code Online (Sandbox Code Playgroud)

如果您知道为什么会发生这种情况,如果您能告诉我,我们将非常感激.

编辑:这是应该将单元格链接到不同视图控制器的功能:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        if self.searchForGroups {

            let detailCell:PFObject = self.filteredGroups.objectAtIndex(indexPath.row) as! PFObject

            let vc = self.storyboard!.instantiateViewControllerWithIdentifier("DynamicCellView") as! DynamicCellView

            vc.GroupId = detailCell.objectId!

            self.presentViewController(vc, animated: false, completion: nil)

        }else{
            //Link to use profile
            let user = self.peopleResults[indexPath.row]
            let vc = self.storyboard!.instantiateViewControllerWithIdentifier("ProfileView") as! profileView
            vc.profileId = user.objectId!
            self.presentViewController(vc, animated: true, completion: nil)
        }
    }
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift uisearchcontroller swift2

4
推荐指数
3
解决办法
6642
查看次数

无法在navigationItem titleView中编辑UISearchController UISearchBar

在navigationItem titleView中设置UISearchController搜索栏时,无法编辑搜索栏.

在我的viewDidLoad中,我正在配置一个UISearchController.

self.searchViewController = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([SearchViewController class])];
self.searchViewController.delegate = self;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.searchViewController];
self.searchController.delegate = self;
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.delegate = self;
self.navigationItem.titleView = self.searchController.searchBar;
Run Code Online (Sandbox Code Playgroud)

我无法点按搜索栏.光标不会出现,也没有用户交互.

奇怪的是,如果我在本地初始化UISearchController而不将其设置为属性,那么我可以编辑搜索栏,只是没有委托回调.

self.searchViewController = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([SearchViewController class])];
self.searchViewController.delegate = self;
UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:self.searchViewController];
searchController.delegate = self;
searchController.searchResultsUpdater = self;
searchController.searchBar.delegate = self;
self.navigationItem.titleView = searchController.searchBar;
Run Code Online (Sandbox Code Playgroud)

另一个有趣的行为是clear按钮有效(如果在初始化时在搜索栏中设置了一些文本).

cocoa-touch objective-c ios uisearchcontroller

4
推荐指数
2
解决办法
2157
查看次数


让搜索栏成为第一响应者

我有一个UISearchController内心UINavigationBar.用户必须点击a UIBarButtonItem,然后我实例化一个新的UIViewController然后呈现它,以便开始搜索.

class ViewController: UIViewController {

  var searchController: UISearchController! 

  override func viewDidLoad() {
    super.viewDidLoad()
    setupSearchController()
  }

  func setupSearchController() {
    searchController = UISearchController(searchResultsController: nil)
    searchController.searchBar.delegate = self
    searchController.searchResultsUpdater = self
    searchController.searchBar.showsCancelButton = true
    searchController.dimsBackgroundDuringPresentation = false
    searchController.hidesNavigationBarDuringPresentation = false

    definesPresentationContext = true
    navigationItem.titleView = searchController.searchBar
  }

}
Run Code Online (Sandbox Code Playgroud)

我事先做了大量研究,但仍无法找到解决方案......

帮助使搜索控制器成为第一个响应者将非常感激.

uisearchbar uisearchcontroller swift3

4
推荐指数
1
解决办法
1941
查看次数

UISearchController需要额外的点击才能成为第一响应者

我将应用程序从一个屏幕切换UISearchBarUISearchController.这是一个tableview控制器.根据设计,我不应该首先在UI上保留搜索栏,除非它被激活,(通常将搜索栏保持为'tableHeaderView'是一种常见的做法).问题是,我有一个搜索按钮,当点击'搜索栏'应该被激活并成为第一响应者.

点击取消按钮时,应从UI中删除它.然而,当我点击导航栏上的"搜索栏按钮"时,UISearchController会激活,提供暗淡的背景但键盘不会出现.我需要再次点击搜索栏以在UI上显示键盘.

这是我的搜索栏按钮动作:

@IBAction func onTapSearch(_ sender: AnyObject) {
    self.view.addSubview(searchController.searchBar)
    searchController.isActive = true
    searchController.becomeFirstResponder()
    isSearchActive = true
    self.navigationController?.setToolbarHidden(true, animated: false)
}
Run Code Online (Sandbox Code Playgroud)

UISearchController在我的viewDidLoad方法中配置.如果您想要查看该部分代码,请告诉我,但这是通常的代码.我确认我不会在resignFirstResponder()任何地方调用任何方法.

uisearchbar ios swift uisearchcontroller swift3

4
推荐指数
1
解决办法
685
查看次数

Swift:向上滚动时显示搜索栏,向下滚动时隐藏它

我是Ios develpomment的新手,我Searchbar在导航项中添加了一个我想要实现的是当我向上滚动时tableview 我要隐藏它Searchbar并在向下滚动时显示它

就像在iPAD/Iphone上的safari效果一样,当向下滚动时显示地址栏并在向上滚动时显示

  let searchController = UISearchController(searchResultsController: nil)
  searchController.searchResultsUpdater = self
  searchController.obscuresBackgroundDuringPresentation = false
  navigationItem.searchController = searchController
  definesPresentationContext = true 
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

ios swift uisearchcontroller

4
推荐指数
1
解决办法
6055
查看次数