Interface Builder 2.0 Problems

Discussion in 'Mac Programming' started by listylister, Jul 6, 2008.

  1. listylister macrumors newbie

    Joined:
    Mar 29, 2008
    #1
    I know this has already been posted elsewhere but I am still having major problems in getting this working. I was wondering if someone could explain exactly what I have to do:

    - I am trying to link a class function into the click event of a button. I have created a Class Object Controller within Interface Builder and typed in the same name as the class in Xcode. I then pressed Ctrl and dragged the line from the button to the class selecting which function i wanted it to process. As far as I can see it's working fine. When I go to run the program nothing happens. It looks to me like the code is not being executed.

    1. Is there a bit of code I can use in order to test this? Like a message box or setting a value within a text box?

    2. How do I actually link my code into Interface Builder. It seemed a lot simpler in previous versions of Interface Builder.


    Thanks in advance for your help :)
     
  2. luckylefty01 macrumors member

    Joined:
    Apr 8, 2008
    #2
    The easy way to test it is to set breakpoints instead the section of the code you think isn't being executed in Xcode and see if they get hit when they should.
     
  3. Soulstorm macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #3
    Into the function of the ClassObjectController, write an NSLog command. Does the NSLog execute when you click that button? That's the kind of test I use...
     
  4. listylister thread starter macrumors newbie

    Joined:
    Mar 29, 2008
    #4
    Ok it seems to be executing the code so I have linked it correctly. However it isn't setting the text correctly. Here is my code:

    AppController.h

    Code:
    #import <Cocoa/Cocoa.h>
    
    
    @interface AppController : NSObject {
    	IBOutlet id textView;
    }
    - (IBAction) clearText: sender;
    @end
    AppController.m

    Code:
    #import "AppController.h"
    
    
    @implementation AppController
    
    - (IBAction) clearText: sender
    {
    	[textView setString: @" "];
    }
    @end
    Any Help Appreciated
     
  5. ghayenga macrumors regular

    Joined:
    Jun 18, 2008
    #5
    Well, since it executed your code when the button got pressed you have connected the button to the IBAction clearText.

    Did you also connect the IBOutlet textView to the actual to the text field instance in Interface Builder? You don't describe control-clicking on your AppController instance in Interface Builder and then dragging from the textView IBOutlet in the AppController to the text field on the window.
     
  6. listylister thread starter macrumors newbie

    Joined:
    Mar 29, 2008
    #6
    Thanks so much! Can't beieve I forgot to do that :p
     
  7. Soulstorm macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #7
    also:

    Code:
     - (IBAction) clearText: sender
    isn't that supposed to look like this?

    Code:
     - (IBAction)clearText:(id)sender
     

Share This Page