0

I'm just beginning X-code (stuck using 3.2.6 for now) and having a similar issue to that described in this post: Connect a UILabel in Interface Builder and XCode?, but still can't figure out where I'm going wrong.

When I ctrl-click on the button and drag to the File's Owner icon, I understand that a menu is supposed to pop up but nothing happens.

Any ideas greatly appreciated.

Here's the code for MyHelloWorldViewController.h:

#import <UIKit/UIKit.h>

@interface MyHelloWorldViewController : UIViewController {

}

- (IBAction) myButtonWasClicked:(id)sender;
{
NSLog(@"button clicked");
}

@end

and MyHelloWorldViewController.m:

#import "MyHelloWorldViewController.h"

@implementation MyHelloWorldViewController

- (void)didReceiveMemoryWarning {
   [super didReceiveMemoryWarning];
}

- (void)dealloc {
    [super dealloc];
}

- (void)viewDidUnload {
}

@end
Community
  • 1
  • 1
Robert
  • 5,278
  • 43
  • 65
  • 115
  • 2
    Any way you can update to a modern version of OS X, Xcode and iOS? 3.2.6 is pretty ancient and pretty much everything has moved on at this point. – bbum Oct 08 '12 at 20:59
  • I prefer using the latest version (4.5) – Jordi Kroon Oct 08 '12 at 21:00
  • I'm kind of stuck with it for now due to my favourite software (Logic) not working properly with Mountain Lion. (Unless anyone knows of a way I can run a newer version of X-code on Snow Leopard?) – Robert Oct 08 '12 at 21:05
  • 2
    Logic 9 is reported as compatible w/Mountain Lion. You could always boot off a separate drive/partition. – bbum Oct 08 '12 at 21:15
  • There's a whole pile of threads on the Apple forums and LUG about gui freezing issues with L9 & ML. As for booting off another partition, it would have to be an external drive as the MBPro's HD is almost full. I'll look into it though. – Robert Oct 08 '12 at 21:19
  • Your .h and .m files look mixed up. – Eiko Oct 08 '12 at 21:28

1 Answers1

2

First, remove the body of the method in your interface method. That file should only be used for declaring the method signature (the implementation goes into the .m file).

Try rewriting it like this:

#import <UIKit/UIKit.h>

@interface MyHelloWorldViewController : UIViewController {

}

- (IBAction) myButtonWasClicked:(id)sender;

@end

and MyHelloWorldViewController.m:

#import "MyHelloWorldViewController.h"

@implementation MyHelloWorldViewController

- (void)didReceiveMemoryWarning {
   [super didReceiveMemoryWarning];
}

- (void)dealloc {
    [super dealloc];
}

- (void)viewDidUnload {
}

- (IBAction) myButtonWasClicked:(id)sender
{
    NSLog(@"button clicked");
}

@end

If that doesn't fix it, double check to make sure you didn't add the button to the MainWindow.xib file. Look at the nib hierarchy window in Interface Builder... does File's Owner say "UIApplication" or "MyHelloWorldViewController?" If it's the former, you are editing the wrong nib. Go back to Xcode and open up MyHelloWorldViewController.xib.

J Shapiro
  • 3,861
  • 1
  • 19
  • 29