JVS
JVS

Reputation: 2682

UITableViewRow displays Buttons without Color

I a have 2 Buttons within my custom TableViewCell. The Buttons are in bright colors. (BackgroundColor set)

enter image description here

However: Running the app - The Buttons color disappear and it becomes white:

enter image description here

I tried to programmatically change the color in viewDidLoad but Xcode doesn't react.

Any Ideas?

Upvotes: 0

Views: 53

Answers (2)

matt
matt

Reputation: 535169

The heart of the problem is that you have introduced buttons but you are also setting the cell's textLabel!.text. You can't mix and match like that. If you're going to use a custom cell, you must use a completely custom cell.

Set the cell's type to Custom, drag a label into it, use a custom cell class, give it an outlet to the label, set this label's text, and all will be well.

Here's my custom cell with an outlet:

class MyCell : UITableViewCell {
    @IBOutlet var label : UILabel!
}

Here's my cellForRow:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! MyCell
    cell.label.text = "Hi" // NOT cell.textLabel!.text
    return cell
}

As you can see, the result is that button appears just fine.

enter image description here

Upvotes: 1

Shades
Shades

Reputation: 5616

You have an extra word in there:

cell.noButton.backgroundColor = UIColor.greenColor()

Upvotes: 0

Related Questions