gpt4 book ai didi

uisearchbar - searchBarSearchButtonClicked 未触发

转载 作者:行者123 更新时间:2023-12-04 03:10:18 26 4
gpt4 key购买 nike

我研究过这个问题。看起来这是一个常见问题,但我尝试过的任何方法都没有奏效。我对 iPhone 应用程序开发和 objective-c 非常陌生。此时我想做的就是在搜索栏字段中输入一个字符串,并在点击键盘上的搜索按钮时返回 NSLog() 中的值。

我的头文件如下所示:

@interface ListingMapViewController : UIViewController <UISearchBarDelegate> 

@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;

@end

我的类文件中有这个:
#import "ListingMapViewController.h"

@interface ListingMapViewController ()


@end

@implementation ListingMapViewController


- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
searchBar.delegate =self;

[self handleSearch:searchBar];
NSLog(@"User searched for %@", searchBar.text);

}

@end

当我单击“搜索”按钮时,没有任何输出。我错过了什么?谢谢。

最佳答案

(在问题编辑中回答。转换为社区维基答案。见 Question with no answers, but issue solved in the comments (or extended in chat))

OP写道:

Solved this by setting the searchBar delegate when the view loads. I guess setting it in searchBarSearchButtonClicked is too late.


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.searchBar setDelegate:self];
//self.searchBar.delegate = self; <-- also works
}

Now when I click the Search button on the keypad the text in the search bar field outputs to NSLog(). Hurray! On to the next challenge.

关于uisearchbar - searchBarSearchButtonClicked 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16380669/

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