adding action block, which should only call after user interaction, but not at the time of initial loading.

Fixing apple crash, where even after deletion, apple not updating number of rows, which is leading to index out of bounds crash.
Adding remove list item method which has specific molecule inside.
This commit is contained in:
Khan, Arshad 2019-09-14 04:55:40 +05:30
parent 52679e95f3
commit b51f1b82f5
3 changed files with 30 additions and 0 deletions

View File

@ -24,6 +24,7 @@ typedef void(^ValueChangeBlock)(void);
@property (nonatomic) BOOL shouldTouchToSwitch;
@property (nullable, copy, nonatomic) ValueChangeBlock valueChangedBlock;
@property (nullable, copy, nonatomic) ValueChangeBlock actionBlock;
+ (nonnull instancetype)mvmSwitchDefault;
+ (nonnull instancetype)mvmSwitchDefaultWithValueChangeBlock:(nullable ValueChangeBlock)block;

View File

@ -169,6 +169,18 @@ const CGFloat SwitchShakeIntensity = 2;
}
[self setState:[json boolForKey:@"state"] animated:false];
self.delegate = delegateObject;
NSDictionary *actionMap = [json dict:@"actionMap"];
if (actionMap) {
[self addTarget:self action:@selector(addCustomAction) forControlEvents:UIControlEventTouchUpInside];
}
}
- (void)addCustomAction {
if (self.actionBlock) {
self.actionBlock();
}
}
+ (CGFloat)estimatedHeightForRow:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject {

View File

@ -149,6 +149,23 @@ open class MoleculeListTemplate: ThreeLayerTableViewController {
}
}
self.tableView?.deleteRows(at: indexPaths, with: animation)
// crash fix
self.tableView?.reloadData()
self.updateViewConstraints()
self.view.layoutIfNeeded()
}
public func removeListItemWhichHas(_ molecule: [AnyHashable : Any], animation: UITableView.RowAnimation) {
var indexPaths: [IndexPath] = []
if let removeIndex = moleculesInfo?.firstIndex(where: { (moleculeInfo) -> Bool in
return NSDictionary(dictionary: molecule).isEqual(to: moleculeInfo.molecule["molecule"] as? [AnyHashable : Any] ?? [:])
}) {
moleculesInfo?.remove(at: removeIndex)
indexPaths.append(IndexPath(row: removeIndex + indexPaths.count, section: 0))
}
self.tableView?.deleteRows(at: indexPaths, with: animation)
// crash fix
self.tableView?.reloadData()
self.updateViewConstraints()
self.view.layoutIfNeeded()
}