0

I need a table cell's accessory type to be compatible with both iOS 7 and 6. I tried to test the availability of an accessory type using the usual address check, but the compiler is complaining

Cannot take the address of an rvalue of type 'NSInteger' (aka 'int')

self.accessoryType = (&UITableViewCellAccessoryDetailButton == nil)
    ? UITableViewCellAccessoryDetailDisclosureButton
    : UITableViewCellAccessoryDetailButton;
Community
  • 1
  • 1
Pwner
  • 3,714
  • 6
  • 41
  • 67

1 Answers1

1

There is no way to check if an enum value exists at runtime. It's simply converted to integers at compile time.

Your only real option is to do some other runtime check that will fail in iOS 6 and succeed in iOS 7 (or later).

Perhaps this:

if ([self respondsToSelector:@selector(separatorInset)]) {
    self.accessoryType = UITableViewCellAccessoryDetailButton; // iOS 7 or later
} else {
    self.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; // iOS 6
}

This solution could possible fail in the future but by then you probably won't be supporting iOS 6 anymore.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • I don't want that on iOS 7. [Look at what it looks like](http://stackoverflow.com/questions/18740594/in-ios7-uitableviewcellaccessorydetaildisclosurebutton-is-divided-into-two-diff). It will include both the chevron and the "i". I only need the "i" by itself. – Pwner Aug 05 '14 at 19:10
  • Strange. I've never seen that in my app. I get just the circled "i". – rmaddy Aug 05 '14 at 19:12
  • Oh wow. I just realized why. I have a custom cell class I use throughout my app and am always generating a custom `accessoryView` based on the `accessoryType`. I never knew over this last year of using iOS 7 that `UITableViewCellAccessoryDetailDisclosureButton` shows both icons. I'll delete this answer shortly. – rmaddy Aug 05 '14 at 19:15
  • The framework developers did not properly upgrade iOS 7 in this regard. They should have kept `UITableViewCellAccessoryDetailDisclosureButton` the same - display only a button. Then they could have introduced `UITableViewCellAccessoryDetailButton` to show both the button and the chevron. But they got it all reversed. – Pwner Aug 05 '14 at 19:15
  • That's a good point. I've updated my answer with one possible workaround. – rmaddy Aug 05 '14 at 19:19