UISearch 栏未调用 searchBarTextDidBeginEditing

发布于 2024-12-14 04:53:46 字数 1572 浏览 3 评论 0原文

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

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

知道会发生什么吗?

一些代码:

controller.hcontroller.m

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

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

@end

@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??");  
}

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

尝试使用以下命令制作简单的应用程序只有搜索栏,显然它可以工作...

编辑:

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

应用程序在 UITabBar 控制器内拥有所有视图控制器,但我不认为这会导致所有这些混乱...

编辑2:

非常奇怪的行为:将 IBAction 函数设置为 UITextfield 的 TouchDown 事件效果很好,但设置EditingDidBegin 的 IBAction 函数永远不会被触发...

为什么无法调用此事件?

I have a simple view controller with a uisearchbar and a uitable.
My problem is that when search bar is tapped I see delegate function searchBarShouldBeginEditing being called but not searchBarTextDidBeginEditing(and because of that keyboard is not opened and search is not editable)

I tried to implement delegate function searchBarShouldBeginEditing returning YES, set searchbar as first responder, but no way I get searchBarTextDidBeginEditing called...

Any idea what could be happening??

Some code:

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??");  
}

Of cousrse my class have plenty more code (that surely is affecting somehow searchbar) but if someone has got similar problems with searchbar it would be very apreciated its response ;)

I tryed to make simple application with only searchbar and obviously it works...

EDITING:

Testing a little bit I discovered that it is not something related with uisearchbar as I added a TextField getting same result (just textFieldShouldStartEditing delegate function being called)

Application has all view controllers inside a UITabBar cotroller, but I do not think this can cause all this mess...

EDITING2:

Really strange behaviour: Setting IBAction function to TouchDown event of a UITextfield works perfectly but setting IBAction function to EditingDidBegin never gets fired...

Why this event could not be called??

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

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

发布评论

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

评论(3

凉风有信 2024-12-21 04:53:46

你设置了委托属性吗?

searchbar.delegate = self;

did you set the delegate property?

searchbar.delegate = self;
儭儭莪哋寶赑 2024-12-21 04:53:46

也许您在某个地方调用[searchbar resignFirstResponder]。我的类似问题就是这种情况。

Maybe you somewhere call [searchbar resignFirstResponder]. It was the case in my similar problem.

你丑哭了我 2024-12-21 04:53:46

当我从独立的 UISearchBar 转换为集成到 UINavigationBar 中的 searchBar 时,我遇到了这个问题。

在转换我的代码时,我仍在分配 UISearchBar 并为其设置委托。我应该做的是配置作为 UISearchController 一部分的 searchBar,并设置它的委托,

self.searchController.searchBar.delegate = self;

一旦我这样做了,我的委托方法就开始触发!

I had this problem when I was converting from a standalone UISearchBar to a searchBar integrated into the UINavigationBar.

In converting my code, I was still allocating the UISearchBar and setting the delegate for that. What I should have been doing was configuring the searchBar that comes as part of of the UISearchController, and setting the delegate of that,

self.searchController.searchBar.delegate = self;

Once I did that, my delegate methods started firing!

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