Can you subclass uinavigationcontroller
You don't have to use IB to do anything except set the UINavigationBar subclass you can still do all of your view set up programmatically. I faced one problem with the above method. Basically, the trick is to subclass UINavigationController. Though I haven't tested it in IB yet, but it is working fine in code. Kind of an amendment to the answers above for those that still want to use initWithRootViewController. Subclass UINavigationController and then:. It's sometimes possible to avoid having to do so by using categories , but not always.
Currently, as far as I know, the only way to set a custom UINavigationBar within a UIViewController is via IB that is, via an archive - it probably shouldn't be that way, but for now, we gotta live with it. This is often fine, but sometimes using IB isn't really feasible.
So, I saw three options:. Option 1 was unfeasible or at least too annoying for me in this case, as I needed to create the UINavigationController programmatically, 2 is a little dangerous and more of a last-resort option in my opinion, so I chose option 3. Here's how:. I just did this within the app delegate, in the simulator.
A better approach to handle that is to have one view controller that you feed the subset of data to display, and when a user drills down it simply creates another instance of the same view controller with that new subset of data. That approach is much better than the idea of having the navigation controller act as a table delegate for each level, because you'd have to do a ton of rewiring moving back and forth and it would require even more work to remember scroll position at each level to boot.
That's why you want to keep drill-downs using multiple instances of view controllers, but multiple instances doesn't have to mean multiple classes. This class is generally used as-is but may be subclassed in iOS 6 and later. As I understand it, subclassing is not encouraged because Objective C allows a subclass too much access to the internal workings of its superclass.
The suggested alternative to writing a subclass is to write a delegate, in this case a UINavigationControllerDelegate. You can then encapsulate the specific behavior you want to extend into this delegate class, and link it up to the UINavigationController whenever you need it.
You can have a data or other object persist while changing views in various ways. Any object in your app can get your app delegate instance with.
0コメント