本文介绍了UIsearch栏不将数据返回到表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..修改代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{静态 NSString *CellIdentifier = @"Cell";UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];如果(单元格==零)cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault重用Identifier:CellIdentifier];如果(被过滤){int rowCount=indexPath.row;Aves *filtrada=[filteredTableData objectAtIndex:rowCount];cell.textLabel.text=filtrada.name;NSLog(@"mostrando:");}别的 {int rowCounter=indexPath.row;Aves *author=[theauthors objectAtIndex:rowCounter];cell.textLabel.text=author.name;}NSLog(@"mostrando:");返回单元格;
}
-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text{如果(文本.长度== 0){isFiltered = FALSE;}别的{isFiltered = true;国际我;[filteredTableData removeAllObjects];for(i=0;[作者数]>i;i++){Aves *name=[theauthors objectAtIndex:i];//NSLog(name.name);NSRange nameRange = [[name.name lowercaseString] rangeOfString:[text lowercaseString]];if(nameRange.length>0){[filteredTableData addObject:name];NSLog(name.name);}}[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];}}
经过一段时间的工作后,我解决了一些问题.刚刚更新了我的代码,问题是 tableView 的重绘,其他一切正常.检查它并给出您的任何想法,请^^
再次感谢您.
解决方案终于修复了.这是我的工作代码,谢谢你们 =)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {静态 NSString *CellIdentifier = @"Cell";UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier];如果(isFiltered==TRUE){int rowCount=indexPath.row;//for (rowCount=0; rowCount<[filteredTableData count]; rowCount++) {Aves *filtrada=[filteredTableData objectAtIndex:rowCount];cell.textLabel.text=filtrada.name;//}}else if(isFiltered==FALSE){int rowCounter=indexPath.row;Aves *author=[theauthors objectAtIndex:rowCounter];cell.textLabel.text=author.name;}返回单元格;}
<块引用>
-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text {
[filteredTableData removeAllObjects];FilteredTableData=[[NSMutableArray alloc]init ];如果(文本.长度== 0){isFiltered = FALSE;}别的{isFiltered = TRUE;国际我;for(i=0;[作者数]>i;i++){Aves * filtrado=[[Aves alloc]init];filtrado=[theauthors objectAtIndex:i];//NSLog(filtrado.name);NSRange nameRange = [[filtrado.name lowercaseString] rangeOfString:[text lowercaseString]];if(nameRange.length>0){[filteredTableData addObject:filtrado];}}[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil
waitUntilDone:NO];}}
Edited code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil)
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
if (isFiltered) {
int rowCount=indexPath.row;
Aves *filtrada=[filteredTableData objectAtIndex:rowCount];
cell.textLabel.text=filtrada.name;
NSLog(@"mostrando: ");
}else {
int rowCounter=indexPath.row;
Aves *author=[theauthors objectAtIndex:rowCounter];
cell.textLabel.text=author.name;
}
NSLog(@"mostrando: ");
return cell;
}
-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text
{
if(text.length == 0)
{
isFiltered = FALSE;
}
else
{
isFiltered = true;
int i;
[filteredTableData removeAllObjects];
for(i=0;[theauthors count]>i;i++)
{
Aves *name=[theauthors objectAtIndex:i];
//NSLog(name.name);
NSRange nameRange = [[name.name lowercaseString] rangeOfString:[text lowercaseString]];
if(nameRange.length>0)
{
[filteredTableData addObject:name];
NSLog(name.name);
}
}
[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
}
}
Edit: After working on it a while I solved some problems.Just updated my code, the problem is the repaint of the tableView, every thing else go ok. Check it and give any ideas you have plz ^^
Thx again for your time.
解决方案finally fixed it. Here is my working code, thx you all =)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
if (isFiltered==TRUE) {
int rowCount=indexPath.row;
//for (rowCount=0; rowCount<[filteredTableData count]; rowCount++) {
Aves *filtrada=[filteredTableData objectAtIndex:rowCount];
cell.textLabel.text=filtrada.name;
//}
}else if(isFiltered==FALSE)
{
int rowCounter=indexPath.row;
Aves *author=[theauthors objectAtIndex:rowCounter];
cell.textLabel.text=author.name;
}
return cell;
}
-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text {
[filteredTableData removeAllObjects]; filteredTableData=[[NSMutableArray alloc]init ]; if(text.length == 0) { isFiltered = FALSE; } else { isFiltered = TRUE; int i; for(i=0;[theauthors count]>i;i++) { Aves * filtrado=[[Aves alloc]init]; filtrado=[theauthors objectAtIndex:i]; //NSLog(filtrado.name); NSRange nameRange = [[filtrado.name lowercaseString] rangeOfString:[text lowercaseString]]; if(nameRange.length>0) { [filteredTableData addObject:filtrado]; } } [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil
waitUntilDone:NO]; } }
这篇关于UIsearch栏不将数据返回到表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论