Comments (7)
There is still no direct means to do validation but you could use the onChange
callback on the row you want to validate and if there is an error with the new value set to that row then you can change the cell.
Do not forget to call row.cellUpdate()
after customizing your cell.
from eureka.
Thanks for the info. My question was more about the appropriate way to update the row. Like if I wanted to change the label color, should I drill down to the label with row.cell.label and set it's tint color? I'm trying to look things up in the code but I'm new to swift and this is the first project I've tried to navigate through.
from eureka.
From inside onChange
you can access to the associated cell row.cell
and change any property.
If you want to persist your change in the time for this specific row i would recommend to change the cell look and feel from inside row.cellUpdate { cell, row in ...... }
clousure that will be executed each time the cell is displayed and any invocation to row.cellUpdate() will not override your cellUpdate
customizations.
To clarify, cellUpdate
customization clousure is invoked at the end of row.updateCell
method and updateCell
method is invoked each time the cell is displayed but you can invoke it (row.updateCell()
) manually to refresh the cell.
from eureka.
I don't understand what is happening with the following. I am calling this code from within viewDidLoad. When the form appears, the text in the label is Phone Number foo. But when I debug, I can see that it goes inside the cellUpdate method before showing the form. If I add a call to updateCell() in viewWillAppear, then the label will say Phone Number bar. Just trying to understand what is happening. Why is the code in the cellIUpdate method running when the form is loaded but it doesn't affect the output on the row until updateCell is called. I tried stepping through with the debugger but it caused Xcode to crash every time.
form <<< LabelRow(RowTag.PhoneNumber.rawValue) {
$0.title = "Phone Number"
$0.value = "foo"
}.cellUpdate { cell, labelRow in
labelRow.value = "bar"
}
from eureka.
When the form is loaded, the tableview is created and the cells will be displayed. This calls the UITableViewDelegate's willDisplayCell:
of the FormViewController, which calls for updateCell
. That's why the cellUpdate block is called after viewDidLoad
.
As for why you initially see "Phone number foo", even though the cellUpdate has been called once, the cellUpdate method is only called after both the row and the cell have finished their normal business.
The timeline looks something like this.
- viewDidLoad -> form gets initialised. (
row.value == "foo"
) - viewWillAppear -> shows cells, so cellWillDisplay is called -> calls updateCell()
- updateCell -> sets cell.detailTextLabel.text to row.value -> (
cell.detailTextLabel.text == "foo"
) - updateCell -> calls cellUpdate, which changes the row.value, but does not update the cell! (
row.value == "bar"
andcell.detailTextLabel.text == "foo"
) - On the next update, things will be as expected. (
row.value == "bar"
andcell.detailTextLabel.text == "bar"
)
Based on this, cellUpdate
should probably be renamed to cellDidUpdate
.
from eureka.
@SpacyRicochet - thanks for the explanation. So I guess my issue is that in cellUpdate I am changing the label via row.value
rather than using cell.detailTextLabel.text
. Thanks again for the explanation. I'm trying to find my way through the codebase but having some difficulty tracing through all the layers. Still learning...
Edit:
I'm trying to figure out the flow for updating a value on the screen. So if a value in my model changes should I call updateCell()
and then in cellUpdate()
I set the value from my model to the cell.detailTextLabel.text
or should I just update the cell.detailTextLabel
instead of calling updateCell()
in the first place. I apologize for all the questions just want to make sure I'm doing thing correctly.
from eureka.
@SpacyRicochet Each Eureka row has a associated UITableViewCell.
Whenever a cell is about to appear willDisplay
is invoked, willDisplay
invokes row.updateCell() that does this steps:
- create the cell.
- invoke cell.Update() // this set up default cell style and makes use of row properties to set up the cell (for example the detailTextLabel.text using row.value)
- Invokes the cellUpdate default clousure.
- invokes cellUpdate clousure of self
as is shown in the code snippet bellow:
override public func updateCell() {
super.updateCell()
cell.update()
customUpdateCell()
RowDefaults.cellUpdate["\(self.dynamicType)"]?(cell, self)
callbackCellUpdate?()
cell.setNeedsLayout()
cell.setNeedsUpdateConstraints()
}
So to persist the custom style changes even when the cell leaves the visible area you should use
row.cellUpdate { cell, row in
...
}
doing that we make sure your code will be invoked at the end of update cycle.
As you might have noticed row.cellUdpate
does not begin a new update cycle automatically so if you want to see the changes you will have to call row.updatecell()
after you set up the row.cellUdpate
clousure.
You can always get the row ( row = form.rowByTag("tag" )) and then access directly the cell property like row.cell.cellProperty = newPropertyValue but probably the update cycle will override it and i do not recommend this approach.
The example project shows several scenarios when we need to make changes on the cells using cellUpdate clousure and updateCell() method.
@SpacyRicochet Thank for collaborating in the explanation. 👍
Regards
from eureka.
Related Issues (20)
- What is the difference between cellUpdate and cellSetup? HOT 1
- TimePickerRow is undeletable in MultivaluedSection HOT 2
- The image of the minus button does not disappear in MultivaluedSection for MultivaluedOptions = [.Insert] HOT 2
- App Store Connect Operation Error: The app references non-public selectors HOT 11
- dyld: Library not loaded: /usr/lib/swift/libswiftCoreGraphics.dylib HOT 2
- Extend cell with another cell
- Section custom header with xib file+class HOT 10
- SegmentedRow crash due to selectedSegmentIndex == -1 HOT 9
- Reordering sections and rows will return the same initial order and not the updated ones HOT 2
- custom Table Inline Row
- SwitchRow Not responding to second time from user interaction HOT 1
- M1 chip Computer + React Native 0.68 + Xcode 14.2 = Compiling Error HOT 1
- Enable BUILD_LIBRARY_FOR_DISTRIBUTION
- Any rule to validate special characters/ numbers in text field in a cell HOT 1
- Food
- How to turn off the capitalization of Section header tiitle? HOT 1
- Bug in iOS 17 Crash app HOT 1
- How to add multivalued .insert options without a multivalued section?
- Index Validation and Safer Collection Handling in Eureka
- Apple privacy manifest file requirement HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eureka.