Reputation:
UIView.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface UIView : UIResponder {
IBOutlet UILabel *endLabel;
IBOutlet UIButton *goButton;
IBOutlet UITextField *textBox1;
IBOutlet UITextField *textBox2;
@property(nonatomic, retain) UILabel *endLabel;
@property(nonatomic, retain) UIButton *goButton;
@property(nonatomic, retain) UITextField *textBox1;
@property(nonatomic, retain) UITextField *textBox2;
}
- (IBAction)goButtonClicked;
@end
UIView.m
#import "UIView.h"
@implementation UIView
@synthesize textBox1, goButton;
@synthesize textBox2, goButton;
@synthesize textBox1, endLabel;
@synthesize textBox2, endLabel;
@synthesize goButton, endLabel;
- (IBAction)goButtonClicked {
}
@end
Upvotes: 1
Views: 233
Reputation: 44769
The first problem is that you're naming your class UIView, which already exists in UIKit. See @Williham's advice on resolving this.
You only need one @synthesize
per property, and when the property name matches the instance variable name, you should only need to do something like this in your .m file:
@synthesize endLabel;
@synthesize goButton;
@synthesize textBox1;
@synthesize textBox2;
Also, you're likely to run into problems getting your IBAction
method to work. To use a method for a target-action linkage, it must have a return type of IBAction
(which you have correct) and accept an id
parameter representing the sender. The canonical method signature looks like this:
- (IBAction) goButtonClicked:(id)sender;
I'd actually recommend a method name that's not explicitly tied to the button that invokes it, especially since there could be other ways to invoke the same action. (For example, if you were writing a desktop application, a key equivalent or menu command could do the same thing.)
Upvotes: 0
Reputation: 29009
Going a bit crazy with the @synthesize
s, are we? I do believe that your main problem here is that @property
declarations need to be after the closing } of @interface
.
I'm surprised the compiler didn't throw up a red flag the size of Greenland, tho'.
Additionally, you probably meant to make a custom subclass of UIView
; I'll use MyView
.
//MyView.m -- correct synthesize declaration
@synthesize textBox1, goButton, textBox2, endLabel;
//MyView.h -- correct interface declaration
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface MyView : UIView {
IBOutlet UILabel *endLabel;
IBOutlet UITextField *textBox1;
IBOutlet UITextField *textBox2;
IBOutlet UIButton *goButton;
}
@property(nonatomic, retain) UIButton *goButton;
@property(nonatomic, retain) UILabel *endLabel;
@property(nonatomic, retain) UITextField *textBox1;
@property(nonatomic, retain) UITextField *textBox2;
@end
Upvotes: 4