Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

listylister

macrumors newbie
Original poster
Mar 29, 2008
17
0
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

macrumors member
Apr 8, 2008
32
0
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

macrumors 68000
Feb 1, 2005
1,887
1
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

macrumors newbie
Original poster
Mar 29, 2008
17
0
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
 

ghayenga

macrumors regular
Jun 18, 2008
190
0
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

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.
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
also:

Code:
 - (IBAction) clearText: sender

isn't that supposed to look like this?

Code:
 - (IBAction)clearText:(id)sender
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.