2011-10-05 2 views

답변

4
// Customize the appearance of table view cells. 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) 
{ 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    UITextField *textField = [[UitextField alloc] init]; 
... 
    textField.delegate = self; 
    textField.tag = indexPath.row; 
    [cell addSubView:textField]; 
} 
- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
    [textField resignFirstResponder]; 
    return YES; 
} 

에서 (becomeFirstResponder) 텍스트 필드 선택한 코드 메이크 위

0

,

NSIndexPath *indexPath = /* Index path of the cell containg the text field */; 
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
// Assuming that you have set the text field's "tag" to 100 
UITextField *textField = (UITextField *)[cell viewWithTag:100]; 
// Make it the first responder 
[textField becomeFirstResponder]; 
0

의 UITextField는 becomeFirstResponder 메시지를 구현 UIResponder에서 상속합니다. 두 번째 jQuery과 cell.Thanks

난이 당신을 도울 수 있습니다 희망
1
// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) 
{ 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

} 
if(indexPath.row==1) 
    { 
     [cell.txtField becomeFirstResponder]; 
    } 
return cell; 
} 

...

+0

를 검색 할 수 있습니다. 이렇게하려면 사용자 정의 셀을 작성해야합니다. 그렇지 않으면 셀에 subview로 textField를 추가 한 다음 becomeFirstResponder를 호출하십시오. 틀 렸으면 고쳐줘. – Mat

+0

@Mat, 정확합니다. –

0

스위프트 4는 : 텍스트 필드를 만들려면 tableview의 첫 번째 응답자는이 확장을 tableView에 추가하기 만하면됩니다.

extension UITableView { 
    func becomeFirstResponderTextField() { 
     outer: for cell in visibleCells { 
      for view in cell.contentView.subviews { 
       if let textfield = view as? UITextField { 
        textfield.becomeFirstResponder() 
        break outer 
       } 
      } 
     } 
    } 
} 
viewDidAppear에서 다음210

() becomeFirstResponderTextField()를 호출

func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(animated) 
    tableView.becomeFirstResponderTextField() 
} 

참고 : 내가 생각하고 visibleCells 당신이 '셀'속성 'txtField'를 가지고 있다고 가정 이러한 방법으로

관련 문제