2012-10-30 3 views
1

매우 초급 obj-c 질문입니다.UITableView에서 UITextField 셀 간 전환

테이블 뷰를 두 섹션 http://uaimage.com/image/c6c9ca23으로 그룹화했습니다. 첫 번째 섹션에는 UITextField가있는 사용자 정의 셀이 있습니다. Input Acessory View를 구현해야합니다. 추가 버튼 "Next", "Prev"(첫 번째 섹션의 텍스트 필드 간 전환) 및 "완료"(키보드 닫기) http://uaimage.com/image/62f08045이있는 키보드의 경우. 질문 : Input 액세서리 버튼을 탭하여 TableView의 첫 번째 섹션에있는 셀의 텍스트 필드간에 전환 할 수있는 가능성을 구현하려면 어떻게해야합니까? 셀이나 텍스트 필드에 태그를 지정해야합니까? 그렇다면 사용자가 입력 액세서리 버튼을 누를 때 어떻게 값을 가져올 수 있습니까? 아니면 이렇게하는 것이 더 나은 방법일까요?

감사합니다, 알렉스 내가 가정

답변

1

이 유가 있다고 3의 UITextField 즉, TXT, tags 0 1 2 txt1, TXT 2; 이제 UITableViewCell *cell을 .h 파일에 추가하십시오.

편집 : 지금 현재있는 tableView 세포의 모든에 textField의 참고 문헌이 대리자 메서드를 추가 얻을 : 이제

-(IBAction)previousBtn:(id)sender 
{ 
    UITextField *txt = (UITextField*)[cell viewWithTag:0]; 
    UITextField *txt1 = (UITextField*)[cell viewWithTag:1]; 
    UITextField *txt2 = (UITextField*)[cell viewWithTag:2]; 
    if(txt.isFirstResponder) 
    { 
    [txt resignFirstResponder]; 
    [txt2 becomeFirstResponder]; 
    } 
    else if(txt1.isFirstResponder) 
    { 
    [txt1 resignFirstResponder]; 
    [txt becomeFirstResponder]; 
    } 
    else if(txt2.isFirstResponder) 
    { 
    [txt2 resignFirstResponder]; 
    [txt1 becomeFirstResponder]; 
    } 
} 

:

입력에서 이제
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
    cell = nil; 
    cell = (UITableViewCell *)[textField superView]; 
    return YES; 
} 

액세서리 이전 버튼 액션을 이렇게 입력 액세서리 다음 버튼 동작에서 다음을 수행하십시오.

-(IBAction)nextBtn:(id)sender 
{ 
    UITextField *txt = (UITextField*)[cell viewWithTag:0]; 
    UITextField *txt1 = (UITextField*)[cell viewWithTag:1]; 
    UITextField *txt2 = (UITextField*)[cell viewWithTag:2]; 

    if(txt.isFirstResponder) 
    { 
    [txt resignFirstResponder]; 
    [txt1 becomeFirstResponder]; 
    } 
    else if(txt1.isFirstResponder) 
    { 
    [txt1 resignFirstResponder]; 
    [txt2 becomeFirstResponder]; 
    } 
    else if(txt2.isFirstResponder) 
    { 
    [txt2 resignFirstResponder]; 
    [txt becomeFirstResponder]; 
    } 
} 
+0

이 코드를 올바르게 이해한다면 프로그래밍 방식으로 모든 텍스트 필드의 속성을 작성해야합니까? – Alex

+1

아니요, u 테이블 참조 –

+1

에서 현재 UITableViewCell의 모든 txt, txt1, txt2를 참조하십시오. –