gpt4 book ai didi

ios - 提交查询后如何使搜索按钮起作用?

转载 作者:行者123 更新时间:2023-11-29 01:25:56 26 4
gpt4 key购买 nike

我在我的应用程序上创建了一个搜索选项,当在搜索栏中输入查询并按下搜索按钮时,它会显示结果。但是,当我再次尝试执行此操作时,它不会搜索。我会保留最后的结果。

这是按下搜索按钮时激活的代码。

-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
NSString *query = [googleBar.text stringByReplacingOccurrencesOfString:@" " withString:@"+"];
UIWebView *webview3=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http:/server.bithumor.co/search/index1.php?query=%@", query]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview3 loadRequest:request];
[self.view addSubview:webview3];
[self.view sendSubviewToBack:webview3];

webview3.scrollView.bounces = NO;
[self webviewListen:webview3];
[searchBar resignFirstResponder];
}

- (void)viewDidLoad {
_barButton.target = self.revealViewController;
_barButton.action = @selector(revealToggle:);

[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

googleBar.delegate = self;

}

为什么这在第一次后不起作用,如何修复?

最佳答案

不要为每次搜索一次又一次地添加 webview。

尝试以下步骤。

i) 声明一个 webview 属性

@property (nonatomic, strong) UIWebView *webView;

ii) 在 ViewDidLoad 方法中添加 webview。

CGRect frame = self.view.bounds;
frame.origin.y = CGRectGetMaxY(self.searchBar.frame);
frame.size.height = CGRectGetHeight(self.view.bounds) - CGRectGetHeight(self.searchBar.bounds);

self.webView =[[UIWebView alloc]initWithFrame:frame];
[self.view addSubview:self.webView];
[self.view bringSubviewToFront:self.webView];
[self.view bringSubviewToFront:self.searchBar];

iii) 在 searchBarSearchButtonClicked 方法中添加以下代码

 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http:/server.bithumor.co/search/index1.php?query=%@", query]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];

希望这对您有所帮助。

关于ios - 提交查询后如何使搜索按钮起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34020532/

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