첫째, 같은 화면에서 사용자에게 표시 너무 많은 반복적 인 정보가없는 디자인을 고려하도록 촉구 -이 앱이보다 직관적 것 . 예를 들어, 선호하지 않는 행을 토글하는 옵션이 있습니다. 이렇게하면 모든 행을 표시하고 즐겨 찾기를 선택하거나 즐겨 찾기에서 선택 만하려는 경우 숨길 수 있습니다.
둘째,이 디자인을 유지하기로 결정한 경우 삽입으로 인한 스크롤을 중지하는 대신 새 행을 삽입하는 동안 테이블보기를 아래로 스크롤하는 것이 좋습니다. 사용자에게는 스크롤이 발생하지 않은 것으로 보입니다. 방법은 다음과 같습니다.
UITableView는 CGPoint 인 ContentOffset 속성을 가지고 있습니다. 이 점의 y 속성은 테이블 뷰가 스크롤되는 거리를 나타내는 CGFloat입니다. 당신이 행을 추가 할 때, 당신의 코드에서, 동시에 너무 화면을 아래로 스크롤 : 행이 선택되어있을 때 애니메이션을 사용하지 않는 경우
// I use some variables for illustrative purposes here (you will need to provide them from your existing code):
// *** put your code to add or remove the row from favorites to your table view data source here ***
// start animation queue
[UIView beginAnimations:nil context:nil];
// check if a row is being added or deleted
if (isAddingRow) {
// if added, call to insert the row into the table view
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:insertedIndexPath] withRowAnimation:UITableViewRowAnimationFade];
// also tell the table view to scroll down the height of a row
[tableView setContentOffset:CGPointMake(tableView.contentOffset.x, tableView.contentOffset.y + kHeightOfRow) animated:YES];
} else {
// if deleted, call to delete the row into the table view
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:deletedIndexPath] withRowAnimation:UITableViewRowAnimationFade];
// also tell the table view to scroll down the height of a row
[tableView setContentOffset:CGPointMake(tableView.contentOffset.x, tableView.contentOffset.y - kHeightOfRow) animated:YES];
}
// launch animations
[UIView commitAnimations];
다른 방법으로, 당신은 실제로 애니메이션을 해제 할 수 있습니다
() 어떤 애니메이션없이 위와 같은 작업을 수행합니다 애니메이션 :
// check if a row is being added or deleted
if (isAddingRow) {
// if added, call to insert the row into the table view
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:insertedIndexPath] withRowAnimation:UITableViewRowAnimationNone];
// also tell the table view to scroll down the height of a row
[tableView setContentOffset:CGPointMake(tableView.contentOffset.x, tableView.contentOffset.y + kHeightOfRow) animated:NO];
} else {
// if deleted, call to delete the row into the table view
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:deletedIndexPath] withRowAnimation:UITableViewRowAnimationNone];
// also tell the table view to scroll down the height of a row
[tableView setContentOffset:CGPointMake(tableView.contentOffset.x, tableView.contentOffset.y - kHeightOfRow) animated:NO];
}
당신은 또한 setContentOffset을 수행 할 수 있습니다 방법을 테이블 뷰 contentSize가있는 tableView 크기보다 큰) (또는 될 것입니다 경우에만 사용할 수 있습니다. 희망이 도움이됩니다!