2013-05-12 2 views
0

"ADD NEW ITEM"셀의 마지막 셀을 탭하면 사용자가 새 데이터를 삽입 할 수있는 테이블보기로 작업하고 있습니다. 각 셀은 내부에 몇 개의 텍스트 필드가 있으며,이 중 하나가 첫 번째 응답자가되면 물론 키보드가 나타납니다. 다음 링크에서 코드를 사용하여 키보드가 편집중인 셀을 덮지 않도록 동적으로 tableview의 크기를 조정하기로 결정했습니다.삽입 섹션이 작동하지 않는 경우 UITableView 키보드 크기 조정

Generic UITableView keyboard resizing algorithm

이 코드는 완벽하게 내가 이전에 추가 된 셀에 텍스트 필드를 탭마다 작동하지만, 나는 새로운 셀을 추가 할 때 프로그래밍 첫 번째로 반응의있는 tableView로의 텍스트 필드를 설정 크기가 조정되지 않습니다. 나는 객관적인 전문가가 아니기 때문에 나는 그것이 무엇이 잘못되었는지 정말로 모른다. 나는 어떤 도움을 주셔서 감사합니다.

이것은 새 셀을 추가하기위한 코드입니다.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
if(indexPath.section == self.dataController.countOfBudgetItemList) 
{ 
    BudgetItem *newItem = [[BudgetItem alloc] initWithName:@"Name of item" price:0 quantity:1 quantityUnit:quantityUnitUnits discount:0 thumbnail:nil]; 

    [self.dataController addBudgetItemListObject:newItem]; 

    [CATransaction begin]; 

    [tableView beginUpdates]; 

    [CATransaction setCompletionBlock: 
    ^{ 
     if(addingNewItem && indexPath.section == editingSectionNumber) 
     { 
      SectionTitleCell *addingNewItemTempCell = (SectionTitleCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:editingSectionNumber]]; 

      [addingNewItemTempCell.productNameTextField becomeFirstResponder]; 
     } 

    }]; 

    if(editingSectionNumber >= 0) 
    { 
     [tableView reloadSections:[NSIndexSet indexSetWithIndex:editingSectionNumber] withRowAnimation:UITableViewRowAnimationFade]; 
    } 

    addingNewItem = YES; 
    editingSectionNumber = indexPath.section; 

    [tableView insertSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade]; 

    [tableView endUpdates]; 

    [CATransaction commit]; 
} 
... 
... 
... 
} 

있는 tableView에서 섹션의 수와 나는 또한 textFieldDidBeginEditing 방법을 사용하고

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
if(editingSectionNumber == section) 
{ 
    return 2; 
} 
else 
{ 
    return 1; 
} 
} 

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
return self.dataController.countOfBudgetItemList + 1; 
} 

각 행 섹션의 수를 관리하는 방법, 그래서이 알고하지 않습니다 this 및 keyboardWillShow 메서드를 트리거하는 이벤트가 동일하므로 문제가 발생할 수 있습니다.

UPDATE : I 전과 애니메이션 후에 tableView.frame의 값을 표시하는 animateWithDuration 메소드 호출을 수정하고, I의 값은 적절하게 "애니메이션"블록으로 변형되는 것으로하지만으로 복귀

그 애니메이션이 완성되면 원래의 값을 유지합니다. 프레임이 원래 크기로 돌아가는 이유는 무엇입니까?

답변

0

글쎄 나는 내 문제에 대한 해결책을 찾았고 누군가가 똑같은 일을 겪을 경우를 대비하여 여기에 게시하기로 결정했다.

기본적으로 모든 코드는 내가 autolayout을 사용하고 있다는 사실을 예상하여 완벽하게 작동합니다. 사용하지 않도록 설정하면 모든 것이 매력처럼 작동합니다.

분명히 새로운 셀을 프로그래밍 방식으로 추가 할 때 tableview는 자동으로 크기가 조정되어 내 코드가 전혀 수행하지 않는 것처럼 보입니다.

관련 문제