附件按钮不隐藏在空的tableview中

时间:2013-04-04 09:25:51

标签: iphone ios6 uitableview

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

- (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];
     }

  }
  }];
  }

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

1 个答案:

答案 0 :(得分:0)

尝试,

if([[[existingResults objectAtIndex:0] valueForKey:@"food_name"] length] > 0)
{
  [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
else
{
  [cell setAccessoryType:UITableViewCellAccessoryNone];
}