jamonholmgren / ProMotion

ProMotion is a RubyMotion gem that makes iPhone development less like Objective-C and more like Ruby.
MIT License
1.26k stars 148 forks source link

Selection style not working #782

Closed afestein closed 8 years ago

afestein commented 8 years ago

Hey guys,

I'm struggling to get selection_style working on a very simple table:

class Team < PM::TableScreen
  def table_data
    [{
      cells: [
        { title: "Boston Celtics", selection_style: :blue },
        { title: "Brooklyn Nets", selection_style: :blue }
      ]
    }]
  end
end

According to the docs I think I'm using it correctly.

I'm expecting that when tapping a row it will turn blue, in reality it adopts the 'highlighted' style for a moment and then goes back to a white background:

screen shot 2016-06-04 at 9 36 35 am

I've checked the value of table_view.allowsSelection and it's set to true.

Does anybody please have any ideas or suggestions?

Many thanks.

andrewhavens commented 8 years ago

Hi @afestein. Are you trying to make it so that when you tap on a row, it stays selected? I don't think UITableViewCells work that way by default. You can try setting keep_selection: true. Alternatively, if you're trying to create a sort of checklist, you might consider changing the accessory view to a checkmark.

afestein commented 8 years ago

Thanks for the reply and suggestions. Yes I was trying to get the cell to stay highlighted and a checkmark accessory was the decoration I needed. I tried this a lot of different ways and couldn't seem to get an accessory to show for a selected cell (and I needed to keep track of the selected cell).

I ended up using a custom cell class extending PM::TableViewCell and then a motion-kit layout to build the background I needed using selectedBackgroundView.

andrewhavens commented 8 years ago

Ah, okay. So you found a solution? Is it okay if we close this issue then?

afestein commented 8 years ago

I did find a solution, but I think it's still unexplained why selection_style: :blue has no effect in the code I'm using above. I'd expect a blue selection style of some kind to appear, but here's what I get:

tphzc4ptd0

andrewhavens commented 8 years ago

The reason is that blue no longer means blue. From the Apple docs:

In iOS 7, the selection color is no longer blue. Use UITableViewCellSelectionStyleDefault instead.

So I guess it's still around for legacy support. If you'd like, do you mind sending a PR that makes note of that change?