2013-08-14 2 views
0

내 목표는 검색 창을 사용하여 tableview의 셀을 필터링하는 것입니다. 요점은 사용자 지정 셀에 단추가 있습니다.이 단추는 숨겨져 있는지 또는 오른쪽 목록에 추가되어 있지 않은지 (다른 uiview입니다)SearchBar 필터링 및 UITableView 셀을 적응?

예를 들어, 더하기 단추를 사용하여 하나의 셀을 추가했습니다. 오른쪽 및 숨기기 플러스 버튼을 클릭하고 검색 창을 사용하여 필터링 할 수 있습니다. 내가 추가 한 셀을 필터링하면 숨겨진 플러스 버튼이 나타납니다. 필터링되기 전에 이미 추가 되었기 때문입니다.

searchBar의 textDidChange 메소드에 일부 코드를 작성했지만 여전히 수행 할 수 없습니다.

어떻게이 목표를 달성 할 수 있습니까?

My tryout code;

-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text 
{ 


     NSArray *cells = [tableView visibleCells]; 

    for (DoctorListCell *cell in cells) 
    { 
     NSLog(@"Cell: %d",cell.plusButton.tag); 

     if(cell.plusButton.tag==0) 
     { 
          [cell.plusButton setHidden:YES]; 

          [tableView reloadData]; 
     } 

    } 

if(text.length == 0) 
{ 
    isFiltered = FALSE; 
} 
else 
{ 
    isFiltered = TRUE; 
    filteredListContent = [[NSMutableArray alloc] init]; 

    for (PlannedCustomer* docs in doctorsTable) 
    { 
     NSRange nameRange = [docs.customerName rangeOfString:text options:NSCaseInsensitiveSearch]; 
     if(nameRange.location != NSNotFound) 
     { 
      [filteredListContent addObject:docs]; 
     } 
    } 
} 

[self.tableView reloadData]; 
} 
+0

여기에 플러스 버튼의 숨겨진 재산 ...을 설정하고 두 번 reloadData를 사용하는 이유는 .. 힘은 당신을 얻을. 좀 더 설명해주세요 .. –

+0

여기 필터링 된 내용이 데이터 소스 인 경우 숨겨진 버튼이있는 셀을 동일하게 유지하려고 시도했습니다 – erdemgc

답변

0

는 그냥 필터링 된 목록에서 세포를 필터링 한 후 cellForRowAtIndexpath 방법으로 세포의 숨겨진 속성을 설정하려고합니다. 또는 당신은 업데이트] tableView:willDisplayCell:forRowAtIndexPath:

에 숨겨진 설정할 수 있습니다 당신의 플러스 버튼을 누른 다음 다음 우선 사용자 정의 셀 클래스에 몇 가지 방법에 숨겨진 속성을 설정 하위 뷰

합니다. 그런 다음 그 방법을 호출하십시오.

또는 그냥 숨기기 대신 더하기 버튼을 제거 할 수 있습니다. 예를 들어

는 :

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSArray *nib; 
    static NSString *cellIdentifier= @"cell"; 

    UITableViewCell *theCell = [self.tblView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if([theCell.contentView subviews]){ 
     for(UIView *view in [theCell.contentView subviews]){ 
      [view removeFromSuperview]; 
     } 
    } 

    if(theCell== nil) 
    { 
     nib = [[NSBundle mainBundle] loadNibNamed:@"Your custom cell name" owner:self options:nil]; 
     theCell = [nib objectAtIndex:0]; 
     theCell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 

    UIButton *btn=(UIButton*)[theCell.contentView viewWithTag:101]; 
if(yourcondition) 
//hide button 
else 
//show button 
} 
+0

내가 오른쪽에 추가 된 필터 셀을 취소하면 숨겨진 버튼이 있지만 버튼이 다시 나타납니다. 나는 그것의 국가 및 재산을 가진 세포를 저장하는 것을 필요로한다 그러나 어떻게? – erdemgc

+0

textDidChange에서 설정 코드를 삭제 했습니까? –

+0

코드를 설정하면 무엇을 의미합니까? – erdemgc

관련 문제