Eureka: Cannot change background color of PushRow

Created on 3 Jan 2016  路  6Comments  路  Source: xmartlabs/Eureka

Hello,
I am trying to change the background color of the PushRow but it is not working. The to.tableView is equal to nil in the onPresent function.

<<< PushRow<Category>("category") {
                $0.title = NSLocalizedString("ENTRY_CATEGORY", comment:"")
                $0.selectorTitle = NSLocalizedString("ENTRY_CATEGORY_SUBTITLE", comment:"")
                $0.options = Array(categories)
                $0.value = defaultCategory
                $0.hidden = Condition.Function([]) { form in
                    return categories.count == 0
                }
            }.onChange{ row in
                if row.value == nil {
                    row.value = CategoryRepository.getNoCategory()
                }
            }.onPresent{ from, to in
                to.tableView?.backgroundColor = UIColor.appBackgroundColor()
                to.view.backgroundColor = UIColor.appBackgroundColor()
            }

Best Regards

appearance onPresent PushRow

Most helpful comment

Hi, I have the same issue and I have done:

 }.onPresent{ from, to in

                to.view.layoutSubviews()

                to.tableView!.backgroundColor = UIColor.lightGrayColor()

            }

And its not working. Any clue? Did I miss something?

All 6 comments

Try this one

.onPresent{ from, to in
     to.view.layoutSubviews()

     // Appearance
     to.tableView?.backgroundColor = UIColor.appBackgroundColor()
}

@schweigechris this actually work, thanks. Still a pain to setup a whole dark theme, check #269

Hi, I have the same issue and I have done:

 }.onPresent{ from, to in

                to.view.layoutSubviews()

                to.tableView!.backgroundColor = UIColor.lightGrayColor()

            }

And its not working. Any clue? Did I miss something?

i'm using 3.1.0 and this works:

<<< PushRow<String>() {
    $0.title = "title"
    $0.options = ["foo", "bar"]
    $0.value = "foo"
    $0.tag = "title"
    }.onPresent({ from, to in
        to.view.layoutSubviews()
        to.tableView?.backgroundColor = UIColor.lightGrayColor()
    })

A quick caveat for anyone using this technique.. layoutSubviews() will trigger setupForm. If you are trying to use the sectionKeyForValue callback, you need to set it BEFORE you call layoutSubviews.

e.g. this won't work

.onPresent { (parentForm, form) in
    // force the framwork to instantiate the tableView
    form.view.layoutSubviews()
    form.tableView.backgroundColor = UIColor.purple

    // oops! too late to set this!
    form.sectionKeyForValue = { option in
         return "FooBar"
   }
}

I am also still trying to find a way to set the color of the title in the Header/Footer views of the PushRow table. Anyone have any luck with that?

Those who are using PushRow table with Header/Footer can use this snippet!

.onPresent { (parentForm, form) in
    // This sets the section for the table.
    form.sectionKeyForValue = { option in
         return "Section Title"
   }
    // After setting up the section, this forces the framework to instantiate the tableView.
    form.view.layoutSubviews()
    form.tableView.backgroundColor = UIColor.lightGray
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

JonathanImperato picture JonathanImperato  路  3Comments

calli23 picture calli23  路  3Comments

smileatom picture smileatom  路  3Comments

iBearKh picture iBearKh  路  3Comments

Tomas1405 picture Tomas1405  路  3Comments