2016-09-26 2 views
0

UITableViewCell의 userInteractionEnabled 인 부모보기가 설정되어있는 동안 하위보기 (이 경우 UITextFields)를 계속 활성 상태로 유지하고 싶습니다 (일반적인 방법으로 편집 가능, 즉 textField 및 키보드가 나타남). 거짓으로.subviews superview userinteraction disabled swift

추가 설명 - 1. xib에서 초기화 된 UITableViewCell이 있습니다.

  1. 이 셀 안에는 세 개의 UITextField와 UIButton이 있습니다.
  2. 어떤 경우에는 (didSelectRowAtIndexPath를 피하기 위해) 셀 상호 작용을 비활성화해야합니다.이 부분에는 아무런 문제가 없습니다.
  3. 3 단계 후에도 셀 안의 모든 하위 뷰가 비활성화됩니다.
  4. 그러나 textFields 안에 텍스트를 입력하고 버튼을 눌러야합니다. 내가 지금까지 무슨 짓을

: 1. 셀에 대해 false로 userInteractionEnabled하고 설정 사용 -

myPersonalInfoExpandedCell.userInteractionEnabled = false 

2. 두 텍스트 필드 firstNameText 및 lastNameText, 나는 userInteraction를 활성화하고 becomeFirstResponder에 firstNameText 설정

(myPersonalInfoExpandedCell as! PersonalInfoExpandedCell).firstNameText.userInteractionEnabled = true 
(myPersonalInfoExpandedCell as! PersonalInfoExpandedCell).lastNameText.userInteractionEnabled = true 
(myPersonalInfoExpandedCell as! PersonalInfoExpandedCell).firstNameText.becomeFirstResponder() 

문제는 userInteractionEnabled 내가 userInteractionEnabled이 표에 대한 거짓 인해 의심하는 작동하지 않는 경우의 텍스트 필드를 들면, ViewCell. becomeFirstResponder()firstNameText에서 작동하지만 셀 내부의 모든 UI 요소에 대한 상호 작용이 필요합니다.

어떻게 할 수 있습니까? 제발 누군가 도와 줄 수 있니?

답변

2

cellSelection을 사용하지 않으려면 willSelectRowAtIndexPath 대리자 메서드를 구현하고 선택하지 않으려는 셀은 nil을 반환합니다. 어떤 조건에서 선택을 비활성화하려는 경우, 선택을 해제 할 행에 대한 indexPath가 있다고 가정합니다. 이 indexPath에 대해서는 nil 만 리턴하면된다. 다음 코드를 참조하십시오.

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
if (indexPath == self.MyIndex) //Check for the index path for the cell you want to disable selection for 
    return nil; 
else 
    return indexPath; 
} 

또한 셀을 강조 표시하지 않으려면이 작업을 수행하십시오. NO 셀에 : 그것은 당신이 setUserInteractionEnabled에없는이 방법을 수행

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

. 당신이 셀에 didSelectRowAtIndexPath 위임 방법을 탭이 방법은 전화를받을 수 없습니다 당신의 텍스트 필드는 여전히

편집

을 활성화 할 것입니다 위의 코드

func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? { 
if (indexPath == self.MyIndex) //Check for the index path for the cell you want to disable selection for 
    return nil; 
else 
    return indexPath; 
} 


cell.selectionStyle = .None 
+0

의 빠른 버전입니다 다음 대답 Shayan 주셔서 감사합니다! 선택하고 싶지 않은 셀에 대해 false를 반환합니까? 나는 그것을 얻지 못했다. 예제를 인용 해 주시겠습니까? –

+0

@LohithKorupolu 내 대답을 편집했습니다. 그것을 한번보세요. 여전히 질문이 있으시면 –

+0

이 작동합니다. 내 textFields를 편집 할 수 있지만 동일한보기 내 UIButton에 문제가 있습니다. 버튼을 탭하면 libC++ abi 예외가 발생합니다.dylib : NSException 유형의 캐치되지 않은 예외로 종료합니다. –