0

在我的应用程序中,我使用了 setAccessoryType,在搜索内容时,它会在带有附件按钮的表格视图中显示一些数据集,当我清除搜索时,表格视图会重新加载。数据已清除,但附件箭头本身会保留在那里。这是我的代码,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"CellIdentifier";
UILabel *l1;
UITableViewCell *cell = (UITableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    l1=[[UILabel alloc]initWithFrame:CGRectMake(0, 5, 690, 40)];
}else{
    l1=[[UILabel alloc]initWithFrame:CGRectMake(0, 5, 310, 40)];
}
l1.textColor=[UIColor whiteColor];
l1.backgroundColor=[UIColor clearColor];
[l1 setFont:[UIFont boldSystemFontOfSize:14.0]];
l1.textAlignment=UITextAlignmentLeft;
l1.text=[[existingResults objectAtIndex:0] valueForKey:@"food_name"];
l1.textColor=[UIColor blackColor];
[cell addSubview:l1];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];    
return cell;
}

tabelview 重载代码

-(void)txttapped:(id)sender{
[[WebService sharedInstance]foodsearch:txtSearch.text withCompletionHandler:^(BOOL result)
 {
 if(result)
 {
     NSLog(@"Success");
     NSManagedObjectContext *context = [[DataAccessLayer sharedInstance] managedObjectContext];
     existingResults = [context fetchObjectsForEntityName:NSStringFromClass([Food class]) withSortColumn:nil withSortDescending:FALSE withPredicate:nil];
     [existingResults retain];
     [tableView reloadData];
     [self.progress hide:YES];
 }
 else
 {
     if (txtSearch.text.length==0)
     {

         [tableView reloadData];// tabelview reloads here
     }
     else
     {
         NSLog(@"Failure");
     UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Alert Message" message:@" Failed" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
     [alertView show];
     [alertView release];
     [self.progress hide:YES];
     }

  }
  }];
  }

tabel没有值时如何隐藏附件视图?请帮我整理一下

4

1 回答 1

0

尝试 ,

if([[[existingResults objectAtIndex:0] valueForKey:@"food_name"] length] > 0)
{
  [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
else
{
  [cell setAccessoryType:UITableViewCellAccessoryNone];
}
于 2013-04-04T09:45:37.693 回答