0

In Interface Builder can I connect between a button in my custom controller (in my custom NIB) and an action method I put in in the MainView NIB (i.e. the AppDelegate)?

Background - In terms of understanding things I am trying to have two (2) customer controllers (with their own views), such that when the iPhone application is launched it starts up with View1. But then on View1 there is Button that if you push it would swap out the View1 controller/view with the View2 controller view. I wanted to cement of understanding of how the AppDelegate with the main Window is allocated a specific View to display which is contained in a custom NIB/controller that I supply.

So I thought I should put the code that swaps out the views (similar to here) as an action in the Application Delegate code (for better or for worst). (i.e. not in either of my view1 or view2 controllers)

Anyway what I find it doesn't seem possible in IB to drag from the View1 button's TOUCH_UP_INSIDE event to the the MainViewNIB. Is it not possible to do this? So again, I'm effectively trying to get a button from one NIB to trigger an action method in another NIB(controller).

Community
  • 1
  • 1
Greg
  • 34,042
  • 79
  • 253
  • 454
  • if you to diaply in view 2 taking the value from view 1, you can do it by declaring the viewcontroller at the click action of the button in view 1.(Correct me if I am wrong). – Milesh Feb 21 '11 at 10:45
  • Correct me if I am wrong, you want to display the data from view1 into view2? or you want to show – Milesh Feb 21 '11 at 10:46
  • not quite - just effectively wanted to try to trigger via a button on view 1 a swap out of the view itself to another view (i.e. view 2) – Greg Feb 21 '11 at 10:46

3 Answers3

1

I know this question is old, but I thought I would note this for anyone else looking for this answer. AppDelegate is not well suited to swapping views. You need to create a root view controller. If you create a new view controller, set it to the root view controller in the AppDelegate, and add the View 1 init stuff to the "ViewDidLoad" section of the new root view controller, you will be able to swap views however you like. You will still need to create a protocol and delegate to send messages back up the chain to the root view controller, but there are plenty of threads here that show you how to do this. Good luck!

JiuJitsuCoder
  • 1,866
  • 14
  • 13
0

Based on what I've seen so far it seems not possible in Interface Builder. Let me know if you agree.

I note that others have suggested some alternatives, however to do justice to the specific question I asked I thought I should propose (tentatively) this answer...

Greg
  • 34,042
  • 79
  • 253
  • 454
0

In a .xib file you can only create connections between objects ("real" objects like your button, labels, etc. or "proxy" objects like File's Owner) that are referenced in that .xib file.

If you set your .xib File's Owner to your app delegate subclass, and call this code to load the nib:

[[NSBundle mainBundle] loadNibNamed:@"MyNib" owner:myAppDelegate options:nil];

then any connections made between your UI items and your app delegate subclass will be filled in using your app delegate object (but only IBOutlets that are nil at the load-time will be set up, loadNibNamed:owner:options: will not change non-nil IBOutlets in the owner object).

Bogatyr
  • 19,255
  • 7
  • 59
  • 72