Editing MainWindow.Xib

Discussion in 'iOS Programming' started by iLoveDeveloping, Dec 17, 2009.

  1. iLoveDeveloping macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #1
    Hey,


    I am doing a navigation type app, and on the MainWindow.xib is the tab bar that i added a 'back' button to.. Now i need to code that window to make the back button work..

    In the classes section i only have

    -RootViewController and AppDelegate.

    So my question is, where can i put the code so that it can be linked to the mainwindow.xib. Because if i put the 'back button' code in the rootviewcontroller.h/m the link shows up on RootViewController.Xib, if i put it in AppDelegate.h/m, it doesn't show up anywhere...

    So where do i put it to show up in IB for MainWindow.Xib?

    Thanks... (i realize this might be a dumb question...)
     
  2. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #2
    If you want to add an action to a part of a view, the view must be connected to the class file. To change which class file the view is connected to, click the far right tab in inspector once you've selected the view.
    There is no such thing as a dumb question. I'm happy to help all developers if I can, whether they are beginners or experts.
     
  3. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #3
    sorry i am not following you? so say i have the code

    Code:
     - (IBAction)goback{
    	[self dismissModalViewControllerAnimated:YES];	
    }
    
    Where do i put this code so that i can connect it to the button i put into the MainWindow.Xib in Interface Builder?
     
  4. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #4
    Open MainWindow.Xib. Click on the view with the button. On the top, click "File>Write Class Files". In these class files that you've just written, put action. Note: There is a comment in the .h file that explains a direction you need to do before you can run it.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Why are you adding a Back button? Navigation controllers already come with one built in.
     
  6. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #6

    No there is not.... This is all i got....
    Code:
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    
    @interface RootViewController : UITableViewController {
        IBOutlet id delegate;
    }
    
    - (IBAction)goback;
    
    @end
     
  7. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #7
    There might be, but not in mine.... There is no back button anywhere, i had to create my own..
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    It won't appear unless you have more than one viewController on the nav stack. But you have a modal view, is that right? And it's defined via MainWindow.xib? Maybe give us more details of your view logic (what appears first, how you move to other views, etc.) so we can better understand what you are trying to achieve and why what you have isn't working.
     
  9. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #9
    Oh i understand what you mean now, yes there is a Default back button 'from the SECOND view on', but i want one on the FIRST view, i have a viewcontroller for the first screen when the App launches, then you press a button and it goes to the Nav screen, but i want to get back from the first nav screen to the first View when the App starts... I am trying to put a back button into the FIRST Nav screen...
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    Hmm, seems to me you have played around with the basic structure that is provided with the Navigation-Based Application template. Normally, with that template, you would not even touch MainWindow.xib. If I was doing this, I would start with the basic template code, add a new UIViewController (w/ view) to contain your "first" screen and present that modally upon application launch. Within that new UIViewController add an IBAction for a Back button which simply dismisses the modal view controller so you end up back at your nav-controlled table view.
     
  11. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #11
    No starting it again is not an option, I have put to much work into it, I just need to put 1 button on a view, I'm not redoing my whole app in a new way just for that! I just need to recreate the viewcontroller from the nav screen! And I need a button to do that... How is that done?
     
  12. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    Have you put that much work into MainWindow.xib? Create a new UIViewController w/ view, move MainWindow stuff to new view, present modally, dismiss on button press, done. (My apologies to Chef Ramsay).
     
  13. iLoveDeveloping thread starter macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #13

    No, i want to dismiss the Nav screen with a button, not the View! The view is perfect and nothing wrong with it!!!

    I can get from the view, to the Nav screen, all i need is how to get back from the Nav screen to the view...??
     
  14. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #14
    How are you presenting the nav screen in the first place? Modally? If so, then just dismiss it, no?
     

Share This Page