views:

4727

answers:

2

I seem to be having an issue with iPhone SDK 2.1 in as far as being able to establish a relationship between a ViewController and a View window. In as far as a Cocoa Touch Class, I went forward and added a UIViewController subclass. I made sure that the target is part of the existing project. Right afterwards I added a User Interfaces -> View XIB. Within the UIViewController I have some straight forward code I literally copy/pasted from sample code elsewhere:

EditViewController.h:

@interface EditorViewController : UIViewController <UITextFieldDelegate> {
    UITextField *field;
}

@property(nonatomic, retain) IBOutlet UITextField *field;
@end

EditViewController.m

#import "EditorViewController.h"

@implementation EditorViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:
         (UIInterfaceOrientation)interfaceOrientation {
   // Return YES for supported orientations
  return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


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


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


@end

As you can tell, it doesn't do much. Now when I click my new xib, and reference a class identity with EditorViewController, no auto complete happens, which to me implies that it has no such awareness of a EditorViewClass. When I attempt to control+click from the view to File's Owners, I get nada.

What are some of the possible idiosyncrasies in this process that I'm overlooking that's not allowing me to outlet my view to a controller?

How would I also ensure that my User Interface View XIB is associated with the project besides seeing the project name checked off as a Target?

+2  A: 

(This doesn't appear to be specific to iPhone -- it's a general class of problem for any platform.)

It's barely clear what this means: "Now when I click my new xib, and reference a class identity with EditorViewController, no auto complete happens, which to me implies that it has no such awareness of a EditorViewClass."

Do you mean that you selected the File's Owner and tried to set its class to EditorViewController, but Interface Builder didn't autocomplete the class name for you?

If this is the case, is the xib file associated with the project?

Other points that aren't directly relevant:

Best practice is now that IBOutlet be associated with the property:

@interface EditorViewController : UIViewController
{
    UITextField *field;
}
@property(nonatomic, retain) IBOutlet UITextField *field;
@end

You should also release the text field in dealloc:

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

The formatting of your question makes it difficult to see what code you've written. The terminology is also "odd" -- outlet is not a verb:

"What are some of the possible idiosyncrasies in this process that I'm overlooking that's not allowing me to outlet my view to a controller?" do you mean: "Is there anything I may have overlooked that means I can't connect my controller's view outlet to the view in Interface Builder?"

mmalc
+1  A: 

It should be as simple as selecting the files owner and entering the name of your class in the class box (it should auto-complete and also be in the drop down menu). Make sure you arent trying to set the class to the view itself.