- (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string
{
_imgSearch.hidden=YES;
if([stringisEqualToString:@"\n"]) {
//判断有无输入
if(_txtSearch.text.length==0){
[MBProgressHUDshowError:@"请输入要搜索的标题"toView:self.view];
}
else{
NSString*inputText = [NSStringstringWithFormat:@"%@",self.txtSearch.text?:@""];
inputText = [inputTextstringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if(inputText.length==0){
[MBProgressHUDshowError:@"不能搜索空白内容"toView:self.view];
}else{
[_txtSearch resignFirstResponder];//收起键盘
// _animationView.hidden=NO;
// _searchBarTable.hidden=NO;
// [self loadSearchData];
if([self isConectNet] ) {
_animationView.hidden=NO;
_searchBarTable.hidden=NO;
_noNetView.hidden=YES;
[selfloadSearchByTitle];
}else{
_searchBarTable.hidden=YES;
_noNetView.hidden=NO;
}
}
}
return NO;
}
return YES;
}
#pragma mark 其他
//判断是否连接网络
-(BOOL)isConectNet{
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
// 一共有四种状态
switch(status) {
case AFNetworkReachabilityStatusNotReachable:
NSLog(@"AFNetworkReachability Not Reachable");
_isConnect=NO;
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"AFNetworkReachability Reachable via WWAN");
_isConnect=YES;
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"AFNetworkReachability Reachable via WiFi");
_isConnect=YES;
break;
case AFNetworkReachabilityStatusUnknown:
default:
_isConnect=NO;
NSLog(@"没有可以的网络");
break;
}
}];
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
return _isConnect;
}