gpt4 book ai didi

ios - UISearch 栏不调用 searchBarTextDidBeginEditing

转载 作者:可可西里 更新时间:2023-11-01 03:38:54 58 4
gpt4 key购买 nike

我有一个带有 uisearchbaruitable 的简单 View Controller 。我的问题是,当点击搜索栏时,我看到委托(delegate)函数 searchBarShouldBeginEditing 被调用但不是 searchBarTextDidBeginEditing(并且由于键盘未打开并且搜索不可编辑)

我尝试实现委托(delegate)函数 searchBarShouldBeginEditing 返回 YES,将搜索栏设置为第一响应者,但我无法调用 searchBarTextDidBeginEditing...

知道会发生什么吗??

部分代码:

Controller .h

@interface ViewController : UIViewController <UISearchBarDelegate>
{
UISearchBar * searchbar;
}

@property (nonatomic, retain) IBOutlet UISearchBar* searchbar;

@end

Controller .m

@synthesize searchbar;

- (BOOL)respondsToSelector:(SEL)sel {
NSLog(@"Queried about %@", NSStringFromSelector(sel));
return [super respondsToSelector:sel];
}

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
NSLog(@"searchBarShouldBeginEditing -Are we getting here??");
return YES;
}
-(void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
NSLog(@"searchBarTextDidBeginEditing -Are we getting here??");
}

当然,我的类(class)有更多的代码(这肯定会以某种方式影响搜索栏)但是如果有人遇到与搜索栏类似的问题,将非常感谢它的响应;)

我尝试只使用搜索栏制作简单的应用程序,显然它有效...

编辑:

稍微测试一下,我发现它与 uisearchbar 无关,因为我添加了一个 TextField 得到了相同的结果(只是调用了 textFieldShouldStartEditing 委托(delegate)函数)

应用程序在 UITabBar Controller 中包含所有 View Controller ,但我不认为这会导致所有这些困惑...

编辑2:

非常奇怪的行为:将 IBAction 函数设置为 UITextfield 的 TouchDown 事件完美无缺,但将 IBAction 函数设置为 EditingDidBegin 永远不会被触发...

为什么不能调用此事件??

最佳答案

是否设置了委托(delegate)属性?

searchbar.delegate = self;

关于ios - UISearch 栏不调用 searchBarTextDidBeginEditing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8007454/

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