使用搜索标签时,我的搜索提醒出现问题。当有人输入他们的搜索字符串并按回车键时,它只会关闭键盘,而您仍然必须按“搜索”(Zoek)按钮,实际上才可以开始网络搜索。
这是我的代码:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *inputText = [[alertView textFieldAtIndex:0] text];
if( [inputText length] >= 1 )
{
[searchview addSubview:indicator];
NSString *urlAddress= @"http://www.sportdirect.com/articles?search=";
urlAddress =[urlAddress stringByAppendingString:inputText];
NSURL *url= [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj= [NSURLRequest requestWithURL:url];
[searchview loadRequest:requestObj];
[[searchview scrollView] setBounces: NO];
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(loading) userInfo:nil repeats:YES];
[TestFlight passCheckpoint:@"Voerde zoekopdracht uit"];
}
}
-(BOOL)textFieldShouldReturn:(UITextField*)textField;
{
[_message dismissWithClickedButtonIndex:(0) animated:YES];
NSString *inputText = [[_message textFieldAtIndex:0] text];
if( [inputText length] >= 1 )
{
[searchview addSubview:indicator];
NSString *urlAddress= @"http://www.sportdirect.com/articles?search=";
urlAddress =[urlAddress stringByAppendingString:inputText];
NSURL *url= [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj= [NSURLRequest requestWithURL:url];
[searchview loadRequest:requestObj];
[[searchview scrollView] setBounces: NO];
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(loading) userInfo:nil repeats:YES];
[TestFlight passCheckpoint:@"Voerde zoekopdracht uit"];
}
[textField resignFirstResponder];
return NO; // We do not want UITextField to insert line-breaks.
}
按下键盘上的返回按钮后,有人知道如何实际执行搜索吗?
提前致谢!
您的课程需要实现UITextFieldDelegate
以获取键盘返回回调。如borrden所建议,可以按以下步骤进行操作
[message textFieldAtIndex:0].delegate = self;
然后实施此方法,
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
// Dismiss the alert view
// Initiate the search
return YES;
}
使用此UIAlertView
方法。请参阅Apple文档
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
需要以编程方式将其关闭时,请在您的警报视图实例上调用此方法。您需要保留message
为ivar,以便在需要时访问它。
希望有帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句