标签: uisearchcontroller

使用UISearchController以编程方式定位UISearchBar

我试图将我的UISearchBar直接置于我的UINavigationBar下,但我遇到的问题是它根本没有出现.我正在使用iOS8的新searchController.

 self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
 self.searchController.searchResultsUpdater = self;
 self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
 self.salesTableView.tableHeaderView = self.searchController.searchBar;
Run Code Online (Sandbox Code Playgroud)

目前我正在使用正确添加到我的UITableView标头的那个,但问题是它滚动表不是我想要的表.我想把它放在我的tableview之上,所以它反而尝试了但现在似乎已经消失了,除非我没有使用正确的值?

 self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
 self.searchController.searchResultsUpdater = self;
 self.searchController.searchBar.frame = CGRectMake(0, 0, self.searchController.searchBar.frame.size.width, 44.0);
 //  self.salesTableView.tableHeaderView = self.searchController.searchBar;
Run Code Online (Sandbox Code Playgroud)

objective-c ios uisearchcontroller

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

实现对CNContact对象的所有值的搜索

我想使用ios9,CNContacts框架对在表视图上获取的所有联系人实施搜索.我可以搜索GivenName,FamilyName等,但是当用户在搜索栏中输入搜索查询时,也想搜索电话号码和电子邮件.正如我们可以在ios9 Apple联系人中搜索电话号码/电子邮件一样.

我知道,因为phonenumbers/emailsaddresses是元组的数组,所以使用NSPredicate格式字符串是不可能的.

iphone uisearchcontroller ios9 swift2

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

如何使用带有objectiveC的uisearchcontroller在ios 9中为tableview添加搜索选项

我有一个tableView成功显示数据,现在我想要的是为它提供搜索功能.UISearchDisplayController在iOS 9中已弃用,我是iOS新手.所以请告诉我这样做的方法.如果有人可以一步一步地提供代码,我很感激它,它也会帮助其他人.这是我的tableView代码.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [airportList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{



    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ci"];

    Details *newDetails = [airportList objectAtIndex:indexPath.row];

    cell.textLabel.text = newDetails.airport;

    return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    Details *newDetails = [airportList objectAtIndex:indexPath.row];
    NSString *selectedText = newDetails.airport;
    [[NSUserDefaults standardUserDefaults] setObject:selectedText forKey:@"st"];
    [[NSUserDefaults standardUserDefaults] synchronize];

    [self dismissViewControllerAnimated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)

objective-c ios uisearchcontroller

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

在segue到新的ViewController之后,搜索栏不会消失

Search Bar塞维到新的后不想消失ViewController.我创建search bar它:

    self.searchBar = UISearchController(searchResultsController: nil)
    self.searchBar.searchResultsUpdater = self
    self.searchBar.dimsBackgroundDuringPresentation = false


    self.navigationController?.extendedLayoutIncludesOpaqueBars = true
    self.tableView.tableHeaderView = self.searchBar.searchBar
    self.tableView.reloadData()
Run Code Online (Sandbox Code Playgroud)

for segue to new View Controllerfrom TableViewControllerI使用此函数:

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

   self.performSegueWithIdentifier("ContentViewCOntroller", sender: self)       
} 
Run Code Online (Sandbox Code Playgroud)

这张照片中的更多细节:

我搜索数据的第一个TableController

第二个带有SearchBar的ViewControler,它可能会降低成本,但它仍然存在

iphone uisearchbar ios swift uisearchcontroller

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

无法将视图推送到searchResultsController

我有一个TableViewController,一个SearchResultsController和一个WebViewController.当我单击TableViewController中的一个单元格时,它会推动WebViewController打开一个与单元格相关的URL.

TableViewController有一个UISearchController,它将结果过滤到SearchResultsController中,但是当在SearchResultsController中单击一个单元格时,WebViewController不会被推送.

以下是SearchResultsController的didSelectRowAtIndexPath的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WebViewController *webViewController = [[WebViewController alloc] init];

    NSString *extensionURL = (self.searchResults[indexPath.row])[@"url"];
    NSURL *baseURL = [NSURL URLWithString:@"http://www.baseurl.com"];
    NSURL *URL = [NSURL URLWithString:extensionURL relativeToURL:baseURL];

    webViewController.title = (self.searchResults[indexPath.row])[@"title"];
    NSLog(@"%@", URL);
    webViewController.URL = URL;
    [self.navigationController pushViewController:webViewController
                                         animated:YES];

}
Run Code Online (Sandbox Code Playgroud)

我包含了NSLog,看看当单击一个单元格时是否发生了什么,它确实在控制台中显示了url.这让我觉得问题出在navigationController上.

在线查看似乎应该将UISearchController包装在UISearchContainerViewController中,然后将其放入navigationController中.我还是应用程序开发的新手,无法弄清楚如何或在何处执行此操作.

我在我的TableViewController的viewDidLoad中调用我的SearchResultsController,如下所示:

- (void)viewDidLoad
{
    [super viewDidLoad];

    SearchResultsViewController *controller = [[SearchResultsViewController alloc] initWithStyle:UITableViewStylePlain];
    [self addObserver:controller forKeyPath:@"results" options:NSKeyValueObservingOptionNew context:nil];

    self.searchController = [[UISearchController alloc] initWithSearchResultsController: controller];
    self.searchController.searchResultsUpdater = self;
    self.searchController.hidesNavigationBarDuringPresentation = NO;
    self.searchController.dimsBackgroundDuringPresentation = NO;
    self.searchController.delegate = self;
    self.definesPresentationContext …
Run Code Online (Sandbox Code Playgroud)

objective-c uinavigationcontroller pushviewcontroller ios uisearchcontroller

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

关闭UISearchController的searchResultsUpdater,需要按两次

按下以显示ViewController搜索功能时,我有一个搜索按钮。该视图控制器包含UITableViewUISearchController

一切正常,但在我选择搜索结果之一之后。我想直接关闭该视图控制器,但是首先选择取消取消,然后再次选择将关闭视图控制器。像下面一样,我只想一个选择解雇。谢谢!

 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        searchViewController.searchBar.resignFirstResponder()
        self.dismissViewControllerAnimated(false, completion: nil)
    }
Run Code Online (Sandbox Code Playgroud)

编辑

let searchViewController = UISearchController(searchResultsController: nil)
func configureSearchController() {
        tableView.tableHeaderView     = searchViewController.searchBar
        searchViewController.delegate = self
        searchViewController.searchResultsUpdater = self
        self.definesPresentationContext = true
        searchViewController.dimsBackgroundDuringPresentation = false
    }
Run Code Online (Sandbox Code Playgroud)

ios swift uisearchcontroller

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

在推送视图上使用UISearchController

UISearchController在我的应用程序中成功实现了一个.我在viewDidLoad我想要使​​用它的视图的方法中将它设置为:

_profileSearchView = [self.storyboard instantiateViewControllerWithIdentifier:@"profileListView"];
[_profileSearchView initSearchController];
self.navigationItem.titleView = _profileSearchView.searchController.searchBar;
Run Code Online (Sandbox Code Playgroud)

initSearchController方法初始化搜索控制器,该控制器属于_profileSearchView并属于_profileSearchView:

- (void) initSearchController {
    _searchController = [[UISearchController alloc] initWithSearchResultsController:self];
    _searchController.delegate = self;
    _searchController.hidesNavigationBarDuringPresentation = NO;

    _searchController.searchBar.delegate = self;
    _searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
    _searchController.searchBar.showsCancelButton = YES;
    _searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
}
Run Code Online (Sandbox Code Playgroud)

如果我在导航控制器的根视图中使用它,这可以正常工作.但是,如果我推送视图并尝试在那里使用它,搜索控制器不会变为活动状态,并且此错误会显示在控制台中:

Warning: Attempt to present <UISearchController: 0x7fb113605220> on <RootViewController: 0x7fb11318a6d0> whose view is not in the window hierarchy!
Run Code Online (Sandbox Code Playgroud)

它抱怨的RootViewController是我推出的根视图.为什么这只在根视图中工作?

更新:根视图控制器self.definesPresentationContext = YES;(推送视图也有),当我从根视图中删除它时,搜索控制器在推送视图上工作.不幸的是,这也打破了其他一些事情,所以我需要把它留在里面.那么我如何允许每个根视图和推送视图都有一个单独的功能搜索控制器?

ios uisearchcontroller

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

[UIView setImage:]:初始化UISearchController时将无法识别的选择器发送到实例

我正在开发具有功能的iOS应用程序,该功能可用于UISearchController提供国家/地区列表的搜索功能。直到最新版本,一切正常。但是现在,在向应用程序中添加了一些新功能之后,我遇到了一个奇怪的错误,该错误导致应用程序崩溃。每当我尝试打电话时UISearchController(searchResultsController:nil),我的应用就会因故崩溃[UIView setImage:]: unrecognized selector sent to instance。我追溯了从先前发行版到现在的所有先前提交,但仍然没有找到罪魁祸首。我想就如何调试此问题提出建议,因为我无法调试进入UISearchController初始化本身。

注意:我没有提供一些代码段,因为我认为这没有必要,我尝试了几种方法,包括UISearchController(searchResultsController:nil)在其他地方调用,删除的使用UISearchController,删除了一些可疑的扩展...以确保swift不会给我带来另一个错误崩溃报告

编辑我的应用程序的目标版本是8.0,我在XCode 7.3.1,MacOS El Capitan上使用swift 2.2

编辑2我尝试切换到,[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];但不幸的是,出于相同的原因仍然崩溃。

编辑3来自Crashlytics的崩溃日志:

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x181ec2db0 __exceptionPreprocess
1  libobjc.A.dylib                0x181527f80 objc_exception_throw
2  CoreFoundation                 0x181ec9c4c __methodDescriptionForSelector
3  CoreFoundation                 0x181ec6bec ___forwarding___
4  CoreFoundation                 0x181dc4c5c _CF_forwarding_prep_0
5  UIKit                          0x18710f9d0 -[UISearchBar(UISearchBarStatic) _updateMagnifyingGlassView]
6  UIKit                          0x18710d778 -[UISearchBar(UISearchBarStatic) _setupSearchField]
7  UIKit                          0x18719d2c8 -[UISearchBar searchField]
8  UIKit                          0x187114684 -[UISearchBar setPlaceholder:]
9 …
Run Code Online (Sandbox Code Playgroud)

ios swift uisearchcontroller

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

UISearchController ResultsController出现在导航栏上

我有一个UISearchController具有自己的自定义结果控制器的工具,而不是在即时视图中过滤内容。

UISearchBar导航栏中正确显示,但是当我开始键入字符的搜索框中,我的自定义控制器出现,填补了整个屏幕,覆盖了导航栏,我输入我的查询到窗口。

这曾经奏效,但最近我将情节提要更改为使用情节提要UINavigationController,进入UITabBarController,然后使用选项卡式控制器。

UITabBarController目前拥有的搜索逻辑,因此它可以通过路线我已经实现了一个协议,在搜索结果采取相应的选项卡的行为。

请注意,下面是我的故事板,自定义搜索结果控制器是位于下方的UITabBarController项目,而右上角的未附加项目则通过库使用,并在内部连接到顶部标签的控制器。

我开始怀疑这种特定的配置是否有效?我可以UINavigationController在前面UITabBarController吗?

我想要一个持久的搜索栏放在顶部,所有共享的搜索代码都放在一个位置(UITabBarController),而不是将UINavigationController放在每个选项卡的前面?

如果这可行,是否有任何想法为什么自定义搜索结果控制器现在覆盖整个屏幕,而不是进入导航栏?

在此处输入图片说明

uiviewcontroller ios uistoryboard uisearchcontroller swift3

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

当UISearchController处于活动状态时显示UIAlertController

我有一个UITableView,在导航栏中有一个UISearchController。表格视图的内容随着用户在搜索栏中键入而更新。当选择一行时,另一个表视图控制器将被推到导航堆栈。在该新的表格视图控制器上,有显示操作表的条形按钮项。问题是,当我在使用搜索控制器后选择一行,然后尝试在新的表格视图控制器上打开操作表时,得到

Attempt to present <UIAlertController: 0x103971800>  on <KYFB_Black_Book.MembersTableViewController: 0x103854c00> which is already presenting (null)
Run Code Online (Sandbox Code Playgroud)

如果我从第一个控制器中选择一行而不进行搜索,然后在第二个控制器上打开操作表,则一切正常。

在第一个控制器的viewDidLoad()中:

searchController = UISearchController(searchResultsController: nil)
        searchController.searchResultsUpdater = self
        searchController.searchBar.tintColor = .white
        searchController.dimsBackgroundDuringPresentation = false
        searchController.hidesNavigationBarDuringPresentation = false
        let searchField = searchController.searchBar.value(forKey: "searchField") as? UITextField
        searchField?.textColor = .white

        if #available(iOS 11.0, *) {
            navigationItem.searchController = searchController
            navigationItem.hidesSearchBarWhenScrolling = false
        } else {
            searchController.searchBar.frame = CGRect(x: 0, y: 0, width: 200.0, height: 44.0)
            searchField?.textColor = .black
            searchController.searchBar.tintColor = .black
            navigationItem.titleView = searchController.searchBar
        }
Run Code Online (Sandbox Code Playgroud)

根据搜索文本更新结果:

@available(iOS 8.0, *) …
Run Code Online (Sandbox Code Playgroud)

ios swift uialertcontroller uisearchcontroller

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