2013-01-16 2 views
0

다음 작동 : 배열에서 표시된 항목이있는 테이블보기가 있습니다. 각 테이블보기 셀의 단추가 bool 값을 반환합니다.검색 창에서 테이블보기를 검색 할 때 index.path.row가 변경되지 않도록하려면 어떻게합니까?

검색 창에서 셀을 검색 할 때 원래 표의 셀 인덱스가 변경되어 indexPath.row이 변경되고 내 단추는 잘못된 경우 indexPath을 사용합니다. 내 버튼에서

관련 코드 : 내 cellForRowAtIndexPath

if (tableView == self.searchDisplayController.searchResultsTableView){ 

    [cell.button setSelected:[story.isBookmarked boolValue]]; 
    cell.button.tag = indexPath.row; 

    } 

else 
{ 

     [cell.button setSelected:[story.isBookmarked boolValue]]; 
    cell.button.tag = indexPath.row; 

} 

답변

0

indexPath.row이 검색 결과에 따라 변경 될 수 있습니다에서

(void)clickedButton:(UIButton*)sender { 

NSLog(@"Row: %d", sender.tag); 

NSIndexPath* indexPath = [NSIndexPath indexPathForRow:sender.tag inSection:0]; 
Stories *story = (Stories *)[self.fetchedResultsController objectAtIndexPath:indexPath]; 
BOOL isSaved = [story.isBookmarked boolValue]; 
story.isBookmarked = [NSNumber numberWithBool:!isSaved]; 

관련 코드입니다. 이 코드를 사용해 indexPath을 얻으십시오.

(void)clickedButton:(UIButton*)sender { 
    UIButton *button = (UIButton *)sender; 
    // Get the UITableViewCell which is the superview of the UITableViewCellContentView which is the superview of the UIButton 
    UITableViewCell *cell = (UITableViewCell*)[[button superview] superview]; 

    NSIndexPath* indexPath = [subListTable indexPathForCell:cell]; 
} 
+0

도움이 되셨습니까? – Avigit

관련 문제