12

I have a custom UITableView subclass in which I override +accessInstanceVariablesDirectly to return NO in order to ensure attributes with no setter cannot be set using KVC.

When removing this table view from the view hierarchy, the app crashes - sometimes - and now for the weird part: only if Accessibility is enabled! (i.e. the Accessibility Inspector is visible, or you have Accessibility enabled on a physical device)

If I do not override +accessInstanceVariablesDirectly, everything works fine. I figured maybe UITableView relies on accessing some instance variables directly - but then what is the point of this method, if I can break superclasses by using it? Is there a way to specify this behavior per-attribute, like +automaticallyNotifiesObserversForKey:? However I am baffled by the fact that this issue only exists when Accessibility is enabled.

I tried analyzing the project with various Instruments, but without success.

You can find a minimal project reproducing the issue here. I would greatly appreciate any pointers on why this is happening or how to achieve what I want nonetheless.

Christian Schnorr
  • 10,768
  • 8
  • 48
  • 83
  • About this line of your code `[self performSelector:@selector(debug) withObject:nil afterDelay:0.1];`. Can you do a `[self performSelectorOnMainThread:withObject:waitUntilDone` instead? I am not on my MAC and I wonder if its because the view is set on possibly a background thread – lead_the_zeppelin Jun 04 '15 at 02:07
  • `-performSelector:` performs its selector on the same thread it has been called. Also this is just an 'optimization' to reproduce the bug, in my real application the views are replaced as a response to a user action which obviously happens on the main thread, – Christian Schnorr Jun 04 '15 at 09:44
  • I run the demo you give in simulator(ios 8.3 iphone5s), it works well, no crash! – Zy Zhao Jun 13 '15 at 05:43
  • Please be sure to file a radar – quellish Jun 13 '15 at 08:59
  • @ZyZhao you have to enable the accessibility inspector. – Christian Schnorr Jun 13 '15 at 09:22
  • I guess you might have seen it, but when zombies are enabled, the following error is logged: `[TableView release]: message sent to deallocated instance `. – VolenD Jun 13 '15 at 10:32
  • @user3584460 So where is the error and how can I fix it? – Christian Schnorr Jun 13 '15 at 13:25
  • It seems that the accessibility inspector keeps reference to the first `tableView` that is created, although it is deallocated. I do not know why this happens - it might as well be a bug with the accessibility inspector. Something else - why do you want to create different instances of `tableView` instead of just creating it once and reusing it? If you reuse the `tableView` you won't get that error. – VolenD Jun 13 '15 at 16:32
  • @user3584460 I can't reuse it in my application. This is just a sample project reproducing the error. – Christian Schnorr Jun 13 '15 at 16:55
  • OK, if the delegate is moved in a separate class, then there is no crash. I tried setting breakpoint for all exceptions and it always stops on the line where the delegate is set (regardless of whether it is `self` or a separate class. – VolenD Jun 13 '15 at 17:27

1 Answers1

2

This issue appears to be fixed in iOS 9.

Christian Schnorr
  • 10,768
  • 8
  • 48
  • 83