KVC in UITableView subclass causing crash with accessibility enabled
Asked Answered
C

1

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.

Chaplain answered 3/6, 2015 at 23:36 Comment(10)
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 threadBlubber
-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,Chaplain
I run the demo you give in simulator(ios 8.3 iphone5s), it works well, no crash!Bezonian
Please be sure to file a radarPatriapatriarch
@ZyZhao you have to enable the accessibility inspector.Chaplain
I guess you might have seen it, but when zombies are enabled, the following error is logged: [TableView release]: message sent to deallocated instance .Lassitude
@user3584460 So where is the error and how can I fix it?Chaplain
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.Lassitude
@user3584460 I can't reuse it in my application. This is just a sample project reproducing the error.Chaplain
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.Lassitude
C
2

This issue appears to be fixed in iOS 9.

Chaplain answered 17/6, 2015 at 11:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.