Three20 搜索范围

发布于 2024-09-10 20:30:38 字数 626 浏览 14 评论 0原文

我正在使用 Three20,并且标准搜索机制正在运行。

TTTableViewController* searchController = [[[TTTableViewController alloc] init] autorelease];
searchController.dataSource = [[[MyDataSource alloc] init] autorelease];
self.searchViewController = searchController;
self.tableView.tableHeaderView = _searchController.searchBar;

我想使用范围。但我在实施它时遇到了困难。通过 Three20 代码,似乎已经内置了 searchdisplaycontroller 。是否有我缺少的方法,例如

-(void)search:(NSString *)text insideScope:(NSString *)scope

如何做我从 searchdisplaycontroller 中提取范围?我尝试使用 searchdisplaycontroller 的委托方法,但数据源未填充表。

有什么想法吗?

谢谢, 豪伊

I'm using Three20 and I've got the standard search mechanism working.

TTTableViewController* searchController = [[[TTTableViewController alloc] init] autorelease];
searchController.dataSource = [[[MyDataSource alloc] init] autorelease];
self.searchViewController = searchController;
self.tableView.tableHeaderView = _searchController.searchBar;

I'd like to use a scope. but I'm having trouble implementing it. Going through the three20 code it appears the searchdisplaycontroller is already built in. Is there a method I'm missing like

-(void)search:(NSString *)text withinScope:(NSString *)scope

How do I pull the scope from the searchdisplaycontroller? I tried using the delegate methods for the searchdisplaycontroller but the datasource isn't populating the table.

Any ideas?

Thanks,
Howie

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安静被遗忘 2024-09-17 20:30:38

经过一番搜索后,我得出的结论是,Three20 核心库中肯定缺少某些内容。我做了一些窥探,发现 UISearchDisplayDelegate 方法位于 TTSearchDisplayController.m 中,不幸的是,当它们将事物交给数据源时,没有合并范围。

以下是我所做的修改:

///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)searchAfterPause {
 _pauseTimer=nil;

// HOWIE MOD
if([self.searchBar.scopeButtonTitlescount])
{
NSString*scope = [[self.searchBarscopeButtonTitles]objectAtIndex:[self.searchBarselectedScopeButtonIndex]];
//NSLog(@"sending text: %@ for scope: %@", self.searchBar.text, scope);
[_searchResultsViewController.dataSource search:self.searchBar.textwithinScope:scope];
}else
{
[_searchResultsViewController.dataSource search:self.searchBar.text];
}

/*
// Original
[_searchResultsViewController.dataSource search:self.searchBar.text];
*/
// /HOWIE MOD
}

然后

///////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)searchDisplayController:(UISearchDisplayController*)controller
        shouldReloadTableForSearchString:(NSString*)searchString {
 if(_pausesBeforeSearching) {
    [selfrestartPauseTimer];
  } else{

// HOWIE MOD
if([self.searchBar.scopeButtonTitlescount])
{
NSString*scope = [[self.searchBarscopeButtonTitles]objectAtIndex:[self.searchBarselectedScopeButtonIndex]];
[_searchResultsViewController.dataSource search:searchString withinScope:scope];
returnYES;
} else
{
[_searchResultsViewController.dataSource search:searchString];
}

/*
// Original
[_searchResultsViewController.dataSource search:searchString];
*/
// / HOWIE MOD

  }
returnNO;
}

并将

///////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)searchDisplayController:(UISearchDisplayController*)controller
        shouldReloadTableForSearchScope:(NSInteger)searchOption {

// HOWIE MOD
if([self.searchBar.scopeButtonTitlescount])
{
NSString*scope = [[self.searchBarscopeButtonTitles] objectAtIndex:searchOption];
[_searchResultsViewController.dataSource search:self.searchBar.textwithinScope:scope];
returnYES;
}else
{
[_searchResultsViewControllerinvalidateModel];
[_searchResultsViewController.dataSource search:self.searchBar.text];
}

/*
// Original
[_searchResultsViewController invalidateModel];
  [_searchResultsViewController.dataSource search:self.searchBar.text];
*/
// / HOWIE MOD
returnNO;
}

我将以下内容添加到 TTTableViewDataSource.h

// HOWIE MOD
- (void)search:(NSString*)text withinScope:(NSString*)scope;
// /HOWIE MOD

以下内容添加到 TTTableViewDataSource.m

// HOWIE MOD
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)search:(NSString*)text withinScope:(NSString*)scope {
}
// /HOWIE MOD

现在我可以创建方法 - (void)search:(NSString*)text insideScope:(NSString* )scope 在我的数据源中,当执行带有范围的搜索时,它将做出相应的响应。当我在 tableview 控制器中实例化搜索控制器时,我还启用了 pausesBeforeSearching ,以便在用户键入时执行搜索之前等待几秒钟。这很有帮助,因为我的搜索是查询服务器,而不是在用户键入时发送每个字符,而是让他们先键入几个字符更有意义。

希望这有帮助。

豪伊

After searching high and low, I came to the conclusion that something must be missing from the core Three20 library. I did a little snooping around and found that the UISearchDisplayDelegate methods are in TTSearchDisplayController.m and unfortunately don't incorporate the scope when they hand things off to the datasource.

Here are the modifications I made:

///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)searchAfterPause {
 _pauseTimer=nil;

// HOWIE MOD
if([self.searchBar.scopeButtonTitlescount])
{
NSString*scope = [[self.searchBarscopeButtonTitles]objectAtIndex:[self.searchBarselectedScopeButtonIndex]];
//NSLog(@"sending text: %@ for scope: %@", self.searchBar.text, scope);
[_searchResultsViewController.dataSource search:self.searchBar.textwithinScope:scope];
}else
{
[_searchResultsViewController.dataSource search:self.searchBar.text];
}

/*
// Original
[_searchResultsViewController.dataSource search:self.searchBar.text];
*/
// /HOWIE MOD
}

and

///////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)searchDisplayController:(UISearchDisplayController*)controller
        shouldReloadTableForSearchString:(NSString*)searchString {
 if(_pausesBeforeSearching) {
    [selfrestartPauseTimer];
  } else{

// HOWIE MOD
if([self.searchBar.scopeButtonTitlescount])
{
NSString*scope = [[self.searchBarscopeButtonTitles]objectAtIndex:[self.searchBarselectedScopeButtonIndex]];
[_searchResultsViewController.dataSource search:searchString withinScope:scope];
returnYES;
} else
{
[_searchResultsViewController.dataSource search:searchString];
}

/*
// Original
[_searchResultsViewController.dataSource search:searchString];
*/
// / HOWIE MOD

  }
returnNO;
}

and

///////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)searchDisplayController:(UISearchDisplayController*)controller
        shouldReloadTableForSearchScope:(NSInteger)searchOption {

// HOWIE MOD
if([self.searchBar.scopeButtonTitlescount])
{
NSString*scope = [[self.searchBarscopeButtonTitles] objectAtIndex:searchOption];
[_searchResultsViewController.dataSource search:self.searchBar.textwithinScope:scope];
returnYES;
}else
{
[_searchResultsViewControllerinvalidateModel];
[_searchResultsViewController.dataSource search:self.searchBar.text];
}

/*
// Original
[_searchResultsViewController invalidateModel];
  [_searchResultsViewController.dataSource search:self.searchBar.text];
*/
// / HOWIE MOD
returnNO;
}

Then I added the following to TTTableViewDataSource.h

// HOWIE MOD
- (void)search:(NSString*)text withinScope:(NSString*)scope;
// /HOWIE MOD

And the following to TTTableViewDataSource.m

// HOWIE MOD
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)search:(NSString*)text withinScope:(NSString*)scope {
}
// /HOWIE MOD

Now I can create the method - (void)search:(NSString*)text withinScope:(NSString*)scope in my datasource and it will respond accordingly as a search with scope is performed. I also enabled pausesBeforeSearching when I instantiate the search controller in my tableview controller so that it waits a couple of seconds before performing the search as a user types. This is helpful since my search is querying a server and rather than send each character as the user types, it makes more sense to let them type a few characters first.

Hope this helps.

Howie

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文