Reputation: 2682
I a have 2 Buttons within my custom TableViewCell. The Buttons are in bright colors. (BackgroundColor set)
However: Running the app - The Buttons color disappear and it becomes white:
I tried to programmatically change the color in viewDidLoad
but Xcode doesn't react.
Any Ideas?
Upvotes: 0
Views: 53
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.
Upvotes: 1
Reputation: 5616
You have an extra word in there:
cell.noButton.backgroundColor = UIColor.greenColor()
Upvotes: 0