Upgrade to Pro — share decks privately, control downloads, hide ads and more …

編集距離による UITableViewの差分更新 - potatotips #37

kazuhiro4949
February 15, 2017
3.5k

編集距離による UITableViewの差分更新 - potatotips #37

デモで使ったサンプルコードはこちら
https://github.com/kazuhiro4949/EditDistanceSample

kazuhiro4949

February 15, 2017
Tweet

Transcript

  1. ฤूڑ཭ͷ ܭࢉΞϧΰϦζϜ w ಈతܭը๏ w .BZFSͷΞϧΰϦζϜ w 8VͷΞϧΰϦζϜ w FUD

    ͦΕͧΕܭࢉྔ͕ҟͳΔ / .ʜ഑ྻ௕ %ʜฤूڑ཭ 1ʜ࡟আ਺ ʜɹɹ0 /. ʜɹɹ0 /% ʜɹɹ0 /1
  2. ࣮ࡍʹܭࢉͯ͠ΈΔ  // ݱࡏςʔϒϧʹදࣔ͞Ε͍ͯΔσʔλ var currentSource = ["a", "b", "c",

    "d", "e"] // ৽͘͠ද͍ࣔͨ͠σʔλ let newSource = ["a", "b", "c", "d", "h", "e", "f", "g"] // ฤूڑ཭ͷܭࢉͯ͠ɺҎԼͷΑ͏ͳσʔλߏ଄Λߏங // let ses = [ // Ses<String>(edit: EditDistance.Edit.common, c: "a", index: 0), // Ses<String>(edit: EditDistance.Edit.common, c: "b", index: 1), // ... // Ses<String>(edit: EditDistance.Edit.add, c: "e", index: 4), // ... // ] let editDistance = EditDistanceCalculator(from: currentSource, to: newSource) let ses = editDistance.compose()
  3. // ςʔϒϧߋ৽ॲཧ͕ೖͬͨҎԼͷܗͷΫϩʔδϟΛ  Ͱ࡞ͬͨܭࢉ݁Ռ TFT ͔Βߏங // let updateHandler =

    { (tableView: UITableView) in // tableView.beginUpdates() // tableView.insertRows(at: [IndexPath(row: 4, section: 0)], with: .fade) // tableView.insertRows(at: [IndexPath(row: 6, section: 0)], with: .fade) // tableView.insertRows(at: [IndexPath(row: 7, section: 0)], with: .fade) // tableView.endUpdates() // } let updateHandler = EditDistanceConverter.convertToTableView(from: ses) // σʔλιʔεΛஔ͖׵͑ͯߋ৽Λ࣮ߦ currentSource = newSource updateHandler(tableView) ࣮ࡍʹܭࢉͯ͠ΈΔ 
  4. ࢀߟࢿྉ w *OTUBHSBN*(-JTU,JU IUUQTHJUIVCDPN*OTUBHSBN*(-JTU,JU  w LIBOMPV/4"SSBZ-POHFTU$PNNPO4VCTFRVFODF IUUQTHJUIVCDPNLIBOMPV/4"SSBZ -POHFTU$PNNPO4VCTFRVFODF 

    w PTUFTMBH$IBOHFTFU IUUQTHJUIVCDPNPTUFTMBH$IBOHFTFU  w KqJOUFS%XJ⒎U IUUQTHJUIVCDPNKqJOUFS%XJ⒎U  w &EJUEJTUBODFBOEFEJUTUFQT IUUQEBWFEFMPOHUVNCMSDPNQPTUFEJU EJTUBODFBOEFEJUTUFQT  w %J⒎BMHPSJUIN IUUQDPOTUFMMBUJPOIBUFOBCMPHDPNFOUSZ  w EJ⒎ͷಈ࡞ݪཧΛ஌ΔʙͲͷΑ͏ʹͯࠩ͠෼Λಋ͖ग़͢ͷ͔ IUUQXXXUIFXPSLqPXDPN IPNFTJOPLBJGBIVBOKJOHEJ⒎OPEPOH[VPZVBOMJXP[IJSVEPOPZPVOJTIJUFDIBGFOXP EBPLJDIVTVOPLB  w 48.BOFS (.ZFST 8.JMMFS "O0 /1 4FRVFODF$PNQBSJTPO"MHPSJUIN