ra1028 / Former

Former is a fully customizable Swift library for easy creating UITableView based form.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change label attributes for FormLabelCell

danmartyn opened this issue · comments

I'm trying to create a Delete button row, by using a FormLabelCell and then setting the textAlignment to be centered and the textColor to be red. However, those changes don't seem to be working. I'm creating my section like this

let deleteSection = SectionFormer().append(rowFormer: LabelRowFormer<FormLabelCell>()
                .configure { row in
                    row.text = "Delete"
                    row.cell.textLabel?.textAlignment = .center
                    row.cell.textLabel?.textColor = .red
                }.onSelected { row in
                    if let indexPath = self.tableView.indexPath(for: row.cell) {
                        self.tableView.deselectRow(at: indexPath, animated: true)
                    }
                    self.startDeleteWorkflow()
            })
            self.former.append(sectionFormer: deleteSection)

When I run this, I get a FormLabelCell, but the "Delete" text is still left aligned and black, not red and centered. Any ideas?

I'm assuming that self.startDeleteWorkflow() is where you are trying to update the cell. If that is the case, you need to call update() or cellUpdate() on the row.

Refer to the README to see how update() and cellUpdate() work.

the startDeleteWorkflow function is where I create an action sheet to confirm if the user wants to do the deletion. Is changing the cell's text label in configure not the correct spot? I'm using update in my other section, but thats to change the content in a text field, not the attributes of it?

I believe when you update the user interface of any row you should be using the update() or cellUpdate() function on the row.

Do you have a repo I can take a look at with the example code you're referring to?

After reading this over once again, I think to accomplish your goal you should use a CustomRowFormer. Check the README and example with custom row, it isn't too complex IMO. If you need help with that, feel free to create a new issue.

If you still need to use LabelRowFormer for some reason, use one of the update() blocks on the cell to modify the cell and its subviews.

Closing due to inactivity.