0

I'm editing a table in iOS Swift 2 using UITableViewRowAction. If they select the action after the action button pops up, I want the current background of the whole cell (not the button popup) to change color. I try accessing it using dequeueReusableCellWithIdentifier but nothing is happening.

let share = UITableViewRowAction(style: .Normal, title: "Showed Up?") { (action, indexPath) in

let cell = tableView.dequeueReusableCellWithIdentifier("secondtableCell", forIndexPath: indexPath) 
cell.backgroundColor = UIColor.redColor()

...the code continues to close later of course. Everything works as expected besides the color change.

Chaim Friedman
  • 720
  • 6
  • 24

1 Answers1

1

Do you register the class in your ViewDidLoad method? If not, go ahead and do this and tell me what you get.

self.tableViewController.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
Mihado
  • 1,487
  • 3
  • 17
  • 30
  • Thanks @Mihado and sorry for the delay here. (I actually broke my shoulder (clavicle) in the meantime!). If I put your code up in the beginning of ViewDidLoad, it messes up other stuff and will stop the table from displaying the necessary info in each cell as well. Plus the background color changes I am looking for aren't happening either. If I put it right in my current code it doesn't mess up anything but it still is not changing background color. – Chaim Friedman Dec 06 '15 at 16:46
  • Oh! I'm very sorry about that and I hope you feel better soon. Chaim, you should try to place this code after you've configured your table view, preferably as the last line in your viewDidLoad. And when you copy and paste the code snippet I left you make sure you're adding the names of your view controller and your cell identifier and not mine, they're probably different. If that doesn't work we can go to chat. – Mihado Dec 06 '15 at 16:51
  • I got it to work now as intended. Instead of using: `dequeueReusableCellWithIdentifier` I just use `cellForRowAtIndexPath` and it works. Thanks for all – Chaim Friedman Dec 06 '15 at 17:20
  • Well in your cellForRowAtIndexPath you need to implement tableview.dequeueReusableCellWithIdentifier to reuse existing cells. I'll post a code snippet shortly – Mihado Dec 06 '15 at 17:23
  • I already have that in a separate function where I do the cell creation. Everything works now. Nothing more looks like is needed inside of this function I'm working on right now, the one using: `editActionsForRowAtIndexPath `. All I needed was a way to grab the specific cell I was editing and that is what I needed `cellForRowAtIndexPath` for. – Chaim Friedman Dec 06 '15 at 17:37
  • Thanks a lot. I could use a blessing! Heavy duty painkillers right now. Surgery later on this week. and I'm typing here with my left hand... – Chaim Friedman Dec 06 '15 at 17:53
  • I missed my footing on top of some commercial steps (concrete) and went flying down from the top to the bottom and landed on my shoulder. There is a lip on top of those stairs that tripped my foot. Hopefully I'll be able to at least get some money. Because leaving it like this means somebody else can trip tomorrow again. Have contacted a lawyer already . – Chaim Friedman Dec 06 '15 at 20:23