Giter VIP home page Giter VIP logo

tablemanager's People

Contributors

nerthase avatar

Watchers

 avatar  avatar

tablemanager's Issues

Come fare un update condizionale?

let cellLabel = CellLabelManager(text: self.user.description)
tmpCellManager.append([cellLabel])
tmpIndexPaths.append(cellLabel.indexPath(inArray: tmpCellManager))
callback(tmpCellManager, tmpIndexPaths)

Questa soluzione funziona molto bene in questo caso specifico. Non mi sembra però opportuno che sia il metodo populateTable a decidere quale cella aggiornare, solitamente questa logica nasce da altre parti del codice. Immagina che dovrà esserci qualche altro parametro passato al metodo, per decidere chi/quando aggiornare.

extension CellManager {
func indexPath(inArray array: [[CellManager]]) -> IndexPath {
let sectionElement = array.first(where: { (section) -> Bool in
section.contains(where: { (row) -> Bool in
row === self
})
})
let sectionIndex = array.index(where: { (section) -> Bool in
section.contains(where: { (row) -> Bool in
row === self
})
})
let rowIndex = sectionElement?.index(where: { (row) -> Bool in
row === self
})
guard let section = sectionIndex, let row = rowIndex else { return IndexPath() }
return IndexPath(row: row, section: section)
}
}

Visto che c'ero ho racchiuso un po' di logica per generare un IndexPath a partire da un elemento all'interno del dataSource

Codice duplicato per passare informazioni da Controller a Cell

class CellFieldManager: CellManager {
var placeholder: String?
var text: String?
var keyboardType: UIKeyboardType = .default // Necessario per poi passarlo a CellField
var isSecureTextEntry: Bool = false // Necessario per poi passarlo a CellField
var blockText: Blocks.stringBlock?

Introducendo il CellManager è necessario duplicare le proprietà che il ViewController passa alla Cell. C'è sempre una sorta di codice duplicato tra Manager e Cell, mentre prima il ViewController passava direttamente queste informazioni alla Cell

Il Manager deve "auto aggiornarsi"

func getCell(tableView: UITableView, indexPath: IndexPath) -> UITableViewCell {
tableView.register(CellField.self)
let cell: CellField = tableView.deque(indexPath)
cell.build(placeholder: self.placeholder, text: self.text, keyboardType: self.keyboardType, isSecureTextEntry: self.isSecureTextEntry, block: {
self.text = $0 // Necessario per mantenere aggiornato CellFieldManager, che altrimenti continuerebbe ad avere un valore vecchio
self.blockText?($0)
})
return cell
}
}

Il Manager non può limitarsi a passare i valori dalla Cell al Controller, ma deve anche preoccuparsi di mantenersi aggiornato. Questo succede perché il valore originale, disponibile nell'oggetto User è disaccoppiato dal valore memorizzato nel Manager.

Ho provato a passare tutto l'oggetto User ma andrebbe implementata una logica ulteriore per individuare la proprietà da considerare. Inoltre questa Cell generica non sarebbe poi adatta ad altri tipi di oggetti, in quanto accoppiata fortemente con User.

Ho provato anche con protocolli/subclass, ma passare il nome del parametro tramite String proprio non mi piace.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.