Coder Social home page Coder Social logo

Comments (7)

mats-claassen avatar mats-claassen commented on May 18, 2024

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.

3cooper avatar 3cooper commented on May 18, 2024

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.

mtnbarreto avatar mtnbarreto commented on May 18, 2024

@3cooper

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.

3cooper avatar 3cooper commented on May 18, 2024

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.

SpacyRicochet avatar SpacyRicochet commented on May 18, 2024

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.

  1. viewDidLoad -> form gets initialised. (row.value == "foo")
  2. viewWillAppear -> shows cells, so cellWillDisplay is called -> calls updateCell()
  3. updateCell -> sets cell.detailTextLabel.text to row.value -> (cell.detailTextLabel.text == "foo")
  4. updateCell -> calls cellUpdate, which changes the row.value, but does not update the cell! (row.value == "bar" and cell.detailTextLabel.text == "foo")
  5. On the next update, things will be as expected. (row.value == "bar" and cell.detailTextLabel.text == "bar")

Based on this, cellUpdate should probably be renamed to cellDidUpdate.

from eureka.

3cooper avatar 3cooper commented on May 18, 2024

@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.

mtnbarreto avatar mtnbarreto commented on May 18, 2024

@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:

  1. create the cell.
  2. 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)
  3. Invokes the cellUpdate default clousure.
  4. 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)

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.