不用UIsearchController实现搜索功能

// 搜索请求

– (void)dd

{

// NSLog(@"post 异步");

@"?name=%@&type=2"

stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL *url1 = [NSURLURLWithString:url];

// post 异步请求 block

// 参数1.request对象

// 参数2.多线程队列NSOperationQueue对象

[NSURLConnectionsendAsynchronousRequest:request1queue:[NSOperationQueuemainQueue] completionHandler:^(NSURLResponse *response,NSData *data,NSError *connectionError) {

NSLog(@"ssssss%@", response);

#pragma mark — 遇到block 一定是回调回来的参数就是你要的数据

// NSMutableDictionary *dic = [NSMutableDictionary dictionary];

// dic = responseObject;

, dic);

searchResultDataArray

NSMutableDictionary *dic1 = [dicobjectForKey:@"info"];

NSMutableDictionary *dic2 = [dic1objectForKey:@"data"];

NSMutableArray *array = [dic2objectForKey:@"items"];

for (NSMutableDictionary *dicin array) {

Comicslist *comics = [[Comicslistalloc]init];

comics.bigbook_id = [NSStringstringWithFormat:@"%@", [dicobjectForKey:@"id"]];

comics.bigbook_name = [dicobjectForKey:@"name"];

comics.bigbook_author = [dicobjectForKey:@"author"];

comics.coverurl = [dicobjectForKey:@"coverurl"];

// NSString *key = [dic objectForKey:@"key_name"];

// comics.key_name = [NSString stringWithFormat:@"%@%@",comics.bigbook_name, comics.bigbook_author];

[self.searchResultDataArrayaddObject:comics];

}

[self.myTableViewreloadData];

}];

}

(5)既然请求下了数据,那么设置tableView吧

// 设置搜索tableView section个数

– (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

{

return1;

}

// 设置搜索tableView的cell

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

staticNSString *cellIdentifier =@"indenfy";

UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:cellIdentifier];

if (cell ==nil) {

alloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier];

}

// 如果有搜索的内容, 显示搜索结果

searchResultDataArray.count != 0) {

Comicslist *comics = [self.searchResultDataArrayobjectAtIndex:indexPath.row];

cell.textLabel.text = comics.bigbook_name;

NSString *str = comics.coverurl;

NSURL *url = [NSURLURLWithString:str];

imageWithDatadataWithContentsOfURL:url]];

cell.imageView.image = image;

}

// 如果没有搜索结果的话, 提示没有查找的内容

else{

cell.;

cell.imageView.image =nil;

}

return cell;

}

// 设置cell高度

– (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

return100;

}

// 设置搜索tableView cell个数

– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

// 如果没有查找到数据, 返回一行

_searchResultDataArray) {

NSLog(@"33333");

return1;

}

// 如果有查找到东西, 显示个数为查找到得个数

_searchResultDataArray

}

,力微休负重,言轻莫劝人。

不用UIsearchController实现搜索功能

相关文章:

你感兴趣的文章:

标签云: