gpt4 book ai didi

ios - 当在 UISearchBar 中粘贴搜索字段时,searchBar textDidChange 被调用两次

转载 作者:行者123 更新时间:2023-11-29 13:38:41 27 4
gpt4 key购买 nike

我在以这种方式从 viewDidLoad 调用的函数中以编程方式创建了一个 UISearchBar

//***************************************
//*** Build the UINavigationBar *
//***************************************
- (void) buildBar {

search = [[UISearchBar alloc] init];
[search sizeToFit];
search.delegate = self;
[[search.subviews objectAtIndex:0] removeFromSuperview];

self.navigationItem.titleView = search;

tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 110.0f, 44.01f)];
tools.barStyle = UIBarStyleBlackTranslucent;
if(tools.subviews.count >0)
{
[[[tools subviews] objectAtIndex:0] removeFromSuperview];
}
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:2];
[buttons addObject:[self editButtonItem]];
bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(activateActions:)];

bi.style = UIBarButtonItemStyleBordered;

[buttons addObject:bi];
[bi release];

[tools setItems:buttons animated:NO];

[buttons release];

UIBarButtonItem *tollbarButtons = [[UIBarButtonItem alloc] initWithCustomView:tools];

self.navigationItem.rightBarButtonItem = tollbarButtons;

[tollbarButtons release];

// [tools release];
// [search release];
}

当我点击搜索字段时,我的 [searchBar textDidChange] 委托(delegate)被调用了两次,我无法弄清楚,它只发生在用户第一次点击搜索字段时,这是正常响应吗? 听到是代码

-(void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
if([searchText length] == 0 && firstTimeSearch == NO ){
firstTimeSearch = YES;
[filterCalls removeAllObjects];
[filterCalls addObjectsFromArray:allCalls];

/* [searchBar performSelector: @selector(resignFirstResponder)
withObject: nil
afterDelay: 0.1];*/
}
else{
firstTimeSearch = NO;
[filterCalls removeAllObjects];
[filteredCallsDetails removeAllObjects];

//
int i = 0;
for(NSDictionary *call in callsDetails ){

// NSNumber *callId = [call objectForKey:@"CallID"];

generalUtils *gu = [[generalUtils alloc]init];
NSArray *callDetail = [[NSArray alloc]initWithArray:[gu getFilteredCallDetails:i :filterCalls :filteredCallsDetails]];

for (NSDictionary *answer in callDetail) {
NSRange r = [[answer objectForKey:@"answer"] rangeOfString:searchText options:NSCaseInsensitiveSearch];
if(r.location != NSNotFound){

[filterCalls addObject:call];
[filteredCallsDetails addObject:callDetail]; }

}

i++;
}
}
[self.tableView reloadData];
}

我在 xCode 4.3.1 中工作我知道我在这个函数中有无法解释的代码,但即使我说它仍然调用了两次,试图解决它但不能罚款 Y乐于得到帮助

最佳答案

使用

 - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar 

代替

 - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText

关于ios - 当在 UISearchBar 中粘贴搜索字段时,searchBar textDidChange 被调用两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9790835/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com