Я не хочу анимацию в блоке begin updates, end updates для uitableview?



У меня есть UITableView, который использует пользовательскую ячейку таблицы, и каждая ячейка имеет UIWebView.



потому что UIWebView взял с собой время для загрузки, я хочу, чтобы избежать перезагрузки их любой ценой.
В некоторых ситуациях у меня все ячейки загружены, но их высоты перепутались.
Поэтому мне нужно "ретранслировать" таблицу без запуска функции "cellForRow".




  1. Я определенно не могу использовать reloadData... как он будет перезагружать клетки снова.

  2. Я попытался tableView.setNeedDisplay, setNeedsLayout и т. д., Ни один из них не может переставить ячейки таблицы

  3. единственный способ, которым это сработало, - это вызвать блок beginupdates/endupdates, этот блок способен ретранслировать мою таблицу без запуска cellForRow! Но, я не хотел анимации! Этот блок производит анимационный эффект, но я не хочу его...


Как я могу решить мою проблему?

546   6  

6 ответов:

[UIView setAnimationsEnabled:NO];
[tableView beginUpdates];
[tableView endUpdates];
[UIView setAnimationsEnabled:YES];

еще один способ сделать это с помощью блоков

Obj-C

[UIView performWithoutAnimation:^{
   [self.tableView beginUpdates];
   [self.tableView endUpdates];
}];

Свифт

UIView.performWithoutAnimation {
    tableView.beginUpdates()
    tableView.endUpdates()   
}

Swifties Мне пришлось сделать следующие работы:

// Sadly, this is not as simple as calling:
//      UIView.setAnimationsEnabled(false)
//      self.tableView.beginUpdates()
//      self.tableView.endUpdates()
//      UIView.setAnimationsEnabled(true)

// We need to disable the animations.
UIView.setAnimationsEnabled(false)
CATransaction.begin()

// And we also need to set the completion block,
CATransaction.setCompletionBlock { () -> Void in
    // of the animation.
    UIView.setAnimationsEnabled(true)
}

// Call the stuff we need to.
self.tableView.beginUpdates()
self.tableView.endUpdates()

// Commit the animation.
CATransaction.commit()

Я предпочитаю иметь плавный переход:

CGPoint offset = self.tableView.contentOffset;
[UIView transitionWithView:self.tableView duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        [self.tableView reloadData];
        self.tableView.contentOffset = offset;
    } completion:nil];

дать ему попробовать.

Я хотел обновить высоту ячейки для раздела 5 и следующий код работал для меня:

UiView.setAnimationsEnabled(False)
self.productTableView.reloadSections(NSIndexSet(index: SectionType.ProductDescription.hashValue), withRowAnimation: UITableViewRowAnimation.None)
self.productTableView.scrollToRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 5), atScrollPosition: UITableViewScrollPosition.Bottom, animated: false)
UIView.setAnimationsEnabled(true)

работа над моим проектом, но не общее решение.

let loc = tableView.contentOffset
UIView.performWithoutAnimation {

    tableView.reloadData()

    tableView.layoutIfNeeded()
    tableView.beginUpdates()
    tableView.endUpdates()

    tableView.layer.removeAllAnimations()
}
tableView.setContentOffset(loc, animated: true)//animation true may perform better

Comments

    Ничего не найдено.