How do I use a modalViewController Identically in Two Controllers?

Posted by Theory on Stack Overflow See other posts from Stack Overflow or by Theory
Published on 2010-04-16T03:05:07Z Indexed on 2010/04/16 3:13 UTC
Read the original article Hit count: 350

I'm using the Three20 TTMessageController in my app. I've figured out how to use it, adding on a bunch of other stuff (including TTMessageControllerDelegate methods and ABPeoplePickerNavigationControllerDelegate methods). It works great for me, after a bit of a struggle to figure it out.

The trouble I'm having now is a design issue: I want to use it identically in two different places, including with the same delegate methods. My current approach is that I've put all the code into a single class inheriting from NSObject, called ComposerProxy, and I'm just having the two controllers that use it use the proxy, like so:

ComposerProxy *proxy = [[ComposerProxy alloc] initWithController:this];
[proxy go];

The go method constructs the TTMessageController, configures it, adds it to a UINavigationController, and presents it:

[self.controller presentModalViewController: navController animated: YES];

This works great, as I have all my code nicely encapsulated in ComposerProxy and I need only the above two lines anywhere I want to use it.

The downside, though, is that I can't dealloc the proxy variable without getting crashes. I can't autorelease it, either: same problem.

So I'm wondering if my proxy approach is a poor one. How does one normally encapsulate a bunch of behaviors like this without requiring a lot of duplicate code in the classes that use it? Do I need to add a delegate class to my ComposerProxy and make the controller responsible for dismissing the modal view controller in a hypothetical composerDidFinish method or some such?

Many TIA!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c