【问题标题】:UITableView Not Scrolling With UISearchBarUITableView 不使用 UISearchBar 滚动
【发布时间】:2010-06-30 06:02:47
【问题描述】:

我想要实现的是一个向上移动并覆盖 UINavBar 的 UISearchBar,并在其右侧包含一个取消按钮。一切顺利,直到我使用以下代码行:

searchDC = [[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self] autorelease];

最终发生的是 UITableView 不会滚动,但其他一切都按预期运行。如果我删除那条线,我的导航栏是可见的,搜索栏就在它下面,也没有取消按钮。

有什么想法吗?

搜索栏的绘制代码为:

self.navigationItem.title = @"Search";
searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.bounds.size.width, 44.0f)] autorelease];
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
searchBar.keyboardType = UIKeyboardTypeAlphabet;
searchBar.delegate = self;
[searchBar becomeFirstResponder];

tableView.tableHeaderView = searchBar;
tableView.tableHeaderView.frame = CGRectMake(0.f, 0.f, 480.f, 44.f);
searchDC = [[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self] autorelease];
searchDC.searchResultsDataSource = self;
searchDC.searchResultsDelegate = self;
searchDC.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
searchDC.searchResultsTableView.scrollEnabled = YES;

overlayView.frame = CGRectMake(0, 50, 320, 480);
[self.view addSubview:overlayView];
[self.view bringSubviewToFront:overlayView];

【问题讨论】:

    标签: ios objective-c uitableview cocoa-touch uisearchbar


    【解决方案1】:

    没有足够的信息来回答这个问题。您需要在设置 UISearchDisplayController 的位置显示 UIViewController 或 UINavigation Controller 代码(.h 和 .m)。

    编辑:

    您完全错误地实现了这一点。苹果有一个很好的例子来说明如何实现这个http://developer.apple.com/iphone/library/samplecode/TableSearch/Introduction/Intro.html

    【讨论】:

    • 抱歉,我已经修复了原帖
    • HTTP 404 找不到您要查找的页面。
    【解决方案2】:

    来自 Apple 的文档,

    Delegate for the search display controller (delegate), which responds to events such the starting or ending of a search, and the showing or hiding of the search interface.

    delegate 设置为您的UITableViewController

     searchDC.delegate = self;
    

    还将searchDC的searchBar添加到tableView的headerView中

     [self.tableView setTableHeaderView:searchDC.searchBar];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-05
      • 2014-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      • 2021-02-14
      相关资源
      最近更新 更多