PDA

View Full Version : Interface Builder 2.0 Problems




listylister
Jul 6, 2008, 09:02 AM
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 :)



luckylefty01
Jul 7, 2008, 02:22 AM
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.

Soulstorm
Jul 7, 2008, 02:50 AM
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...

listylister
Jul 7, 2008, 07:16 AM
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

#import <Cocoa/Cocoa.h>


@interface AppController : NSObject {
IBOutlet id textView;
}
- (IBAction) clearText: sender;
@end

AppController.m

#import "AppController.h"


@implementation AppController

- (IBAction) clearText: sender
{
[textView setString: @" "];
}
@end

Any Help Appreciated

ghayenga
Jul 7, 2008, 10:24 AM
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

#import <Cocoa/Cocoa.h>


@interface AppController : NSObject {
IBOutlet id textView;
}
- (IBAction) clearText: sender;
@end

AppController.m

#import "AppController.h"


@implementation AppController

- (IBAction) clearText: sender
{
[textView setString: @" "];
}
@end

Any Help Appreciated

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.

listylister
Jul 7, 2008, 11:04 AM
Thanks so much! Can't beieve I forgot to do that :P

Soulstorm
Jul 7, 2008, 04:50 PM
also:

- (IBAction) clearText: sender

isn't that supposed to look like this?

- (IBAction)clearText:(id)sender