Skip to content

Commit d57fe82

Browse files
committed
Enable to reload data
1 parent 0df12d6 commit d57fe82

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

macaron/MacaronViewController.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,30 @@ open class MacaronViewController: UIViewController, UITableViewDelegate, UITable
1212
private var macaronTableView: UITableView!
1313
private var macaronCellData: [MacaronCellDataType] = []
1414
private var cellHeight: [CGFloat] = []
15+
private var registeredCell = [String]()
1516

1617
public func initialize(tableView: UITableView, cellData: [MacaronCellDataType]) {
1718
macaronTableView = tableView
1819
macaronTableView.delegate = self
1920
macaronTableView.dataSource = self
21+
reloadData(cellData: cellData)
22+
}
23+
24+
public func reloadData(cellData: [MacaronCellDataType]) {
2025
macaronCellData = cellData
2126
cellHeight = [CGFloat](repeating: 0.0, count: cellData.count)
2227
for cell in Set(cellData.map{$0.CellClassName}) {
28+
if registeredCell.contains(cell) {
29+
continue
30+
}
31+
registeredCell.append(cell)
2332
var bundle = Bundle.main
2433
if let _ = Config.MacaronBundle.path(forResource: cell, ofType: "nib") {
2534
bundle = Config.MacaronBundle
2635
}
27-
tableView.register(UINib(nibName: cell, bundle: bundle), forCellReuseIdentifier: cell)
36+
macaronTableView.register(UINib(nibName: cell, bundle: bundle), forCellReuseIdentifier: cell)
2837
}
29-
tableView.reloadData()
38+
macaronTableView.reloadData()
3039
}
3140

3241
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

0 commit comments

Comments
 (0)