Can I define a new outgoing action to connect in Interface Builder?
Ok, what I actually want to do is change the tab when a user presses a button in an AlertView I pop up.
My custom FirstViewController creates the AlertView and sets itself as the delegate. I want FirstViewController to take some action, but then I also want to change the tab in my tab view interface. FirstViewController doesn't know about the tab interface at all. I could add a connection so that FirstViewController does know about it, but th开发者_JAVA技巧at seems inelegant to me.
What I would like to do is define an outgoing action on FirstViewController, and be able to connect it in Interface Builder to an IBAction on some object outside FirstViewController that does know about the tab interface, maybe my app delegate, maybe another custom view controller I have called MenuViewController. Then I would call it from FirstViewController alertView:clickedButtonAtIndex:
In my code I know how to create IBOutlets, outgoing connections to other objects. I know how to create IBActions, incoming action targets that other objects can call. What I want is to be able to create an "IBOutletAction", that I can point to an IBAction in another object. UIControls somehow define "IBOutletActions" that tell Interface Builder what events they have that can be connected to other objects' IBActions. Can I do the same thing, or is it achieved for UIControls by some secret mojo that only works for Apple classes? If I can't duplicate it exactly, what's your recommendation for the simplest approximation? I can define a -setTarget:(id)target forAction:(SEL)action on FirstViewController and link it up in code, but ideally I want something that can be set in Interface Builder.
By "Tab view interface" do you mean the UITabBarController? If so, all view controllers know about the top level tab bar via the tabBarController property, so you can get to it that way. Instead it might make sense to add a method to the class that owns the UITabBarController and ask it to do what you want to do, for better software structure. For instance, if its the app delegate that instantiated it, just get to that and invoke a method that will manipulate the tab bar for you (this, IMHO, is better structured because the logic and specifics of manipulating this are not contained within your class. For instance, if you changed your framework which had a different presentation for the tab bar (Three20 style?) that member function could encapsulate that change and your class wouldn't know any difference).
精彩评论