2014-10-14 3 views
1

나는 인 UITableViewCell을 가지고 있습니다. 이 셀에는 편집 할 수있는 최대 3 자리 문자열이 포함되어 있습니다. 지금까지는 좋았습니다;) 키보드에 부착 된 UIToolbar에서 이전 및 다음 버튼을 만들었습니다. 키보드도 올바르게 표시됩니다. 내 휴대폰에서iOS UITableViewCell (텍스트 필드 포함)

- (void) didPressNext:(Cell *)cell 
{ 
    NSIndexPath *indexPath = [_tableView indexPathForCell:cell]; 
    NSInteger maxRows = [_tableView numberOfRowsInSection:indexPath.section]; 
    NSInteger maxSections = [_tableView numberOfSections]; 

    if (maxRows > (indexPath.row + 1)) { //In the same section 
     NSIndexPath *next = [NSIndexPath indexPathForItem:indexPath.row + 1 inSection:indexPath.section]; 
     Cell * nextCell = (Cell *)[_tableView cellForRowAtIndexPath:next]; 

     [_tableView scrollToRowAtIndexPath:next atScrollPosition:UITableViewScrollPositionBottom animated:NO]; 
     [nextCell becomeFirstResponder]; 

    } else if (maxSections > (indexPath.section + 1)) { //Is there a next section 
     maxRows = [_tableView numberOfRowsInSection:indexPath.section + 1]; 
     if (maxRows != 0) { //If there are any 
      NSIndexPath *next = [NSIndexPath indexPathForItem:0 inSection:indexPath.section + 1]; 

      Cell * nextCell = (Cell *)[_tableView cellForRowAtIndexPath:next]; 
      if (nextCell.shirtNumber && !nextCell.shirtNumber.hidden) { //Contains a shirtNumber? 
       [_tableView scrollToRowAtIndexPath:next atScrollPosition:UITableViewScrollPositionBottom animated:NO]; 

       [nextCell becomeFirstResponder]; 
      } 
     } 
    } 
} 

나는 이러한 방법을 덮어 :

- (BOOL) canBecomeFirstResponder{ 
    return YES; 
} 

- (BOOL) isFirstResponder 
{ 
    return [_shirtNumber isFirstResponder]; 
} 

- (BOOL) becomeFirstResponder 
{ 
    return [_shirtNumber becomeFirstResponder]; 
} 

- (BOOL) resignFirstResponder 
{ 
    return [_shirtNumber resignFirstResponder]; 
} 

그리고이 과정이 제대로 작동 시간의 일부 때로는 내가 두 번 누르면

이제 다음 구현을 위해 내가 할. 애니메이션이 항상 작동하므로 다음 indexPath를 정확하게 계산했습니다.

내가 뭘 잘못하고 있니?

질문은 : u는 분명 셀은 첫 번째로 반응 할 기운 [nextCell becomeFirstResponder]; 을 가지고있는 경우 첫 번째의 끝에

+0

여기에 어떤 질문이 있는지 명확하지 않습니다. 분명히 할 수 있습니까? 작동시키기 위해 버튼을 두 번 눌러야하는 경우가 있습니까? – Stonz2

답변

0

"왜 때때로 becomeFirstResponder 더 일을하지 않고 반환하지 않습니다 그 것이다." 이어야하며 [nextCell.shirtNumber becomeFirstResponder];이어야합니다.

+0

셀을 확장하여 텍스트 필드로 전달했습니다. 내 요점을 명확히해야하는 두 번째 코드를 확인하십시오. 두 번째 시간은 내가 지금 고칠 것입니다. – Haagenti

+0

u가 맞습니다. – user4043206