LoginSignup
11
12

More than 5 years have passed since last update.

SwiftBond v4系でアニメーションせずにUITableViewの更新ができるようになりました!

Last updated at Posted at 2015-12-02

ViewBindingで有名なSwiftBondですが、つい3時間前にアニメーションせずにUITableViewとUICollectionViewの更新ができるようになりました。

実はこれ、v3系ではできていたんですが、Swift2.0にアップデートすると上げざるをえないv4系ではできなくなっていたんですね。。。

それが今日できるようになりました。よかった。

v4.3.0

Support for non-animatable collection/table view updates.

スクリーンショット 2015-12-03 02.41.05.png

具体的なコードはこちら(要点のみ)

いつも通りtableViewにdataSourceをバインドして、、でも、今回は、proxyDataSourceを指定します。proxyDataSourceはBNDTableViewProxyDelegateに準拠している必要があります。

dataSource.bindTo(tableView, proxyDataSource: self) { (indexPath, dataSource, tableView) -> UITableViewCell in
    let string = dataSource[indexPath.section][indexPath.row]
    ...
    return cell
}

そして、BNDTableViewProxyDelegateのこちらのメソッドを実装します。

func shouldReloadInsteadOfUpdateTableView(tableView: UITableView) -> Bool {
    return true
}

「UITableViewのUpdateじゃなくて、Reloadを行う」って意味のメソッドです。これだけ!やった!

プルリク送りました

実はこれ僕がpull request送りました。ただ、議論の末にマージされた時点ではだいぶ形が変わりましたが、実現したいことは作者と同じでブレていなかったので最終的にマージされました〜。よかった!

v4系に上げてうまく動かないと苦しんでいる誰かのお役に立てれば!

SwiftBond

SwiftBond/Bond

11
12
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
12