Tag Archives: ios-sdk

Note on SplitViewController and Auto Reference Counting

SplitViewController is a easy tool to make a nice interface for iPad, but I have some negative comment on it:

- It is singleton, and it occupy the whole window. I cannot add something else on it. Of cause, it force a simpler design.

- It cause the work flow different between iPhone and iPad version, which cannot be solved by storyboard entirely.

There is a special case for auto reference counting that would produce error:

- make a weak property
@property (weak) UIView* myView

- alloc and assign an instance to it directly
self.myView = [[UIView alloc] init];

- the instance is released immediately!

It is because the reference counting is zero right after the assignment, and ARC don’t recognize that should be retained and auto-released. In order to solve this, change the code to:

- create a local variable to store the newly alloc-ed instance
UIView *view = [[UIView alloc] init];
The reference counting of the instance is 1 and being auto-released.

- assign that to the property
self.myView = view;