-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash at changeValue of SwitchCell #2208
Comments
Hi, could you please provide exact crash error. Also, are you using a custom nib file for this row? Some code to reproduce the error would also be helpful as it does not seem to happen in the Example project. |
not sure if what your asking is this message this is what is in the crash report
we are not using nibswe do everything by code Also I'm not able to reproduce in my iPhone XR, but I see this sort of error ocurring more often than it should, but not actually related with a SwitchRow. More as when we reload and refresh. This is the reason why I've start limiting my refresh/reloads to smaller parts of the form rather than update the whole form. For instanceWe use realm with observers. |
OK. So there are two variables which could be nil but shouldn't in that row. If you have been able to debug this, would you know which variable is nil? |
Not sure if i understood correctly, you are refering "Two variables" as -- edit -- |
Right, I was referring to |
I'm going back to talk about reload refreshing the sections cause we are also gettting this issue which may as well be related with our implementation
So I slightly change our code to share it here struct MySection : FormSectionProtocol {
var title: String = "Section title"
var tag : String { return title }
var vc: FormViewController
let sectionType : Sections = .sectionTypeId
init(vc : FormViewController) {
self.vc = vc
generate()
}
enum rows {
case firstRowType // image cell
case secondRowType // switch cell
var row : BaseRow {
switch self {
case .firstRowType:
return ImageRow(){ row in
row.cell.textTitle = "row title1"
row.cell.cellImage = #imageLiteral(resourceName: "image")
}
.onCellSelection({ cell,row in
row.deselect()
// navigate
})
case .secondRowType:
let row = SwitchRow(){ row in
row.cell.height = { 60 }
row.cell.imageView?.image = #imageLiteral(resourceName: "image")
row.title = "this is the second row"
row.cell.switchControl.isOn = true // TODO: fetch value
row.value = row.cell.switchControl.isOn
}.onCellSelection {
cell,row in
cell.switchControl.setOn(!cell.switchControl.isOn, animated: true)
row.value = cell.switchControl.isOn
row.deselect()
}.onChange { row in
guard let cell = row.cell else { return }
let currentValue = true // TODO: fetch value
guard currentValue != row.value else { return } // prevent rollback from triggering the api request
remoteProcedure(status: cell.switchControl.isOn) {
success in
DispatchQueue.main.async {
switch success {
case true: break // update value
case false:
cell.switchControl.setOn(!cell.switchControl.isOn, animated: true) // roll back to previous value
row.value = cell.switchControl.isOn // keeps row value consistent, switch value doesnt do it automatically
}
}
}
}
.cellUpdate { cell,row in
cell.textLabel?.textColor = UIColor.Global.Text
}
row.tag = "myRow"
return row
}
}
}
mutating func generate()
{
self.title = title
self.vc.form +++ self.section
self.populate()
}
func populate() {
if let mySection = vc.form.sectionBy(tag: tag) {
mySection <<< rows.firstRowType.row
mySection <<< rows.secondRowType.row
}
}
func reload() {
UIView.performWithoutAnimation {
vc.tableView.beginUpdates()
if let mySection = vc.form.sectionBy(tag: tag) {
mySection.removeAll()
}
populate()
vc.tableView.reloadData() // this might be causing a crash, should not be called inside the begin end (?)
vc.tableView.endUpdates()
}
}
} |
Thanks for posting the code. First comment on it is that you are accessing the SwitchRow() { row in
row.title = "..."
row.value = ...
}.cellSetup { row, cell in
cell.height = { 60 }
...
} As for the |
Just an update |
Hey, it is correct to use either cellSetup or cellUpdate and for certain modifications you need cellUpdate. Just don't access the cell in the row's initializer block. SwitchRow() { row in
row.title = "..."
row.value = ...
row.cell.... = ... // <-- Don't do this
} |
Eureka (5.3.4)
Xcode Version 13.2.1 (13C100)
iOS 15.3.0
I'm having some crashes which I believe are related with refreshing the form/sections
This is the code from eureka:
any ideas?
The text was updated successfully, but these errors were encountered: