2012-05-11 4 views
2

셀 수가 많은 테이블보기가 있습니다. 모달 뷰 컨트롤러를 사용하여 새 셀을 추가하면 사용자에게 새로 추가 된 셀을 표시하고 싶습니다. 이렇게하려면 테이블보기를 새 셀로 스크롤하고 선택하고 즉시 선택 취소하십시오.테이블보기를 셀로 스크롤 한 다음 셀을 깜박입니다.

는 지금, 나는 시간 초과 간격 후 deselectRowAtIndexPath 내 테이블보기를 보내고있다 :이 작업을 수행 할 수있는 더 좋은 방법이 있다면

- (IBAction)selectRow 
{ 
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:7 inSection:0]; 
    [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop]; 
    [self performSelector:@selector(deselectRow:) withObject:indexPath afterDelay:1.0f]; 
} 

- (void)deselectRow:(NSIndexPath *)indexPath 
{ 
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 

내가 궁금하네요. 잘 작동하지만 정적 타이머를 사용하여 때로는 시간이 다른 작업을 수행하는 것을 좋아하지 않습니다 (예 : 테이블이 매우 긴 경우).

편집 :selectRowAtIndexPath:animated:scrollPositionUITableView 대리자 메서드가 실행되지 않도록합니다. tableView:didSelectRowAtIndexPath: 또는 scrollViewDidEndDecelerating:도 호출되지 않습니다. 워드 프로세서에서하십시오 tableView:willSelectRowAtIndexPath: 또는 tableView:didSelectRowAtIndexPath: 메시지를받을 수있는 대리자를 발생하지 않습니다이 메서드를 호출

않으며 관찰자에 UITableViewSelectionDidChangeNotification 알림을 보내드립니다.

답변

0

UITableViewDelegateUIScrollViewDelegate의 확장자입니다. UIScrollViewDelegate 메소드 중 하나를 구현하고이를 사용하여 행을 선택 취소 할시기를 결정할 수 있습니다. scrollViewDidEndDecelerating:은 시작하기에 좋은 장소 인 것 같습니다.

또한 개인적으로 1 매개 변수 제한으로 인해 performSelector... 메서드를 제한하고 있습니다. 나는 GCD를 선호한다. 코드는 다음과 같습니다

- (IBAction)selectRow 
{ 
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:7 inSection:0]; 
    [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop]; 
    //deselect the row after a delay 
    double delayInSeconds = 2.0; 
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); 
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
     [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 
}); 

}

+0

감사를 GCD 버전. 스크롤은 사용자가 시작하지 않으므로 불행히도 스크롤 뷰 대리자는 알리지 않습니다. 확인하기 위해 구현했지만 테이블을 수동으로 스크롤 할 때만 호출되었습니다. –

+0

'scrollViewDidScroll :'을 구현하고'contentOffset.y'를 검사하여 셀이 보이는지 확인할 수 있습니다. –

관련 문제