2013-10-02 1 views
1

현재 iPhone 용 음악 플레이어 응용 프로그램을 작성하려고합니다. 디자인의 일부로 노래 목록의 단일 항목을 스 와이프하여 추가 옵션을 표시 할 수 있습니다 (예 : iOS 7 Mail.app).touchesCancelled가 사용자 지정 UIScrollView를 포함하는 사용자 지정 UITableViewCell을 호출했지만 UITableView didSelectRow가 잘못된 셀에서 실행되었습니다.

커스텀 UITableViewCell의 도움으로 이것을 실현했습니다. 여기에는 사용자 정의 UIScrollView와 두 개의 UIView (실제 내용과 "배경 메뉴")가 포함되어 있습니다. 이는 주로 예상대로 작동합니다.

CellScrollView.m

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
    if (![self isDragging]){ 
     [[self superview] touchesBegan:touches withEvent:event]; 
    } 
    [super touchesBegan: touches withEvent: event]; 
} 

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ 
    if (![self isDragging]){ 
     [[self superview] touchesMoved:touches withEvent:event]; 
    } 
    [super touchesMoved: touches withEvent: event]; 
} 

-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ 
    if (![self isDragging]){ 
     [[self superview] touchesCancelled:touches withEvent:event]; 
    } 
    [super touchesCancelled: touches withEvent: event]; 
} 

- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event{ 
    if (![self isDragging]){ 
     [[self superview] touchesEnded:touches withEvent:event]; 
    } 
    [super touchesEnded: touches withEvent: event]; 
} 

을 이제 다음있는 UIScrollView 실제로 노래를 재생하는 옵션을 사용할 수 TableViewCells의 모든 접촉을 취할 듯, 나는 (예를 들어 here 제안으로) 터치 이벤트를 전달 내 문제는 다음과 같습니다. 목록의 셀을 누른 채로 스크롤하면 미디어 플레이어가 예상대로 재생되지 않습니다. 그러나 목록의 다른 항목을 탭하면 내가 밟은 제목은 재생되지 않지만 처음에는 누른 상태에서 스크롤을 시작합니다. 이것은 탭 앤 홀드 (tap-and-hold) 후에 더 이상 탭하여 스크롤을 스크롤하지 않고 멈추지 않는 경우에만 발생합니다 (로그에서 '예기치 않은 터치 단계'가 발생합니다.) 이것이 마침내 탭을 취소 한 것입니다. -보류).

이 동작을 해결할 수있는 방법이 있습니까? (정상적인 UITableViewCell을 사용하면 모든 것이 잘 작동하므로 UIScrollView가 모든 것을 손상시키는 것 같군요)?

답변

1

나는 당신과 똑같은 문제가있었습니다.

내가 수정 한 것은 셀의 델리게이트로 tableview를 포함하는 뷰 컨트롤러를 설정하는 것입니다.

그럼 셀에 대리자 선택기를 설정하여 탭 동작을 내 tableview가 포함 된보기 컨트롤러에 전달합니다.

@class GameSequenceCell;

@protocol CustomCellDelegate <NSObject> 
- (void)didSelectCell:(CustomCell *)sender; 
@end 

@interface CustomCell : UITableViewCell 
/* 
* Some stuffs 
*/ 
@end 

그런 다음 셀에 직접 UITapGestureRecognizer를 추가했습니다. 이 작업은 셀의 초기화시 수행되어야합니다. 그때 셀 구현

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]; 
    if (self) [self prepareForFirstUse]; 
    return self; 
} 

-(id)initWithCoder:(NSCoder *)aDecoder 
{ 
    self = [super initWithCoder:aDecoder]; 
    if (self) [self prepareForFirstUse]; 
    return self; 
} 

-(void)prepareForFirstUse 
{ 
    /* 
    * The tap gesture recognizer is needed to be able to tap on the scroll view in the cell 
    * Calling the singleTapGestureCaptured will trigger the tableView:didSelectRowAtIndexPath: 
    * of the EventPanelVC tableview delegate. 
    */ 
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)]; 
    [self addGestureRecognizer:singleTap]; 
} 

:

- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture 
{ 
    [self.delegate didSelectCell:self]; 
} 

세포 인에서의 tableview 함유 뷰 컨트롤러 인 대표.

지금 셀의 모든 탭 제스처 사로 잡았하고 뷰 컨트롤러에서 I 구현 :

- (void)didSelectCell:(CustomCell *)sender; 
{ 
    NSIndexPath *indexPathOfTouchedCell = [self.fetchedResultsController indexPathForObject:sender.object]; 
    if(indexPathOfTouchedCell) 
    { 
     [self.tableView selectRowAtIndexPath:indexPathOfTouchedCell animated:YES scrollPosition:UITableViewScrollPositionNone]; 
     [self tableView:self.tableView didSelectRowAtIndexPath:indexPathOfTouchedCell]; 
    } 
} 

이 내가이 문제를 해결하는 방법입니다.

+0

자세한 답변을 보내 주셔서 감사합니다. 그 동안 UIPanGestureRecognizer로 전환하여 "손으로"내 견해를 스크롤했습니다. 잠시 동안이 솔루션을 고수 하겠지만, scrollView를 사용하면 다시 볼 수있는 것처럼 보였습니다. 다시 돌아와 다시 시도해 볼 수 있습니다. – dorbeetle

관련 문제