I am new to Objective-C and am very noobish.
I am trying to pass the text from a UITextField in the SecondViewController to the FirstViewController.
What I have right now is:
(SecondViewController.h)
#interface SecondViewController : UIViewController <UITextFieldDelegate>
#property (weak, nonatomic) IBOutlet UITextField *PrimaryPhone;
#end
(FirstViewController.m)
#import "SecondViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize PrimaryPhone;
Then there is the other default items included within the .m file.
But where it says:
#synthesize PrimaryPhone;
Xcode gives me the error in the title. (Property implementation must have its declaration in interface 'FirstViewController')
You must have the property primaryPhone inside FirstViewController.h
Alternatively within the interface
#interface FirstViewController ()
#end
In FirstViewController.m
What you are trying to synthesize is belonging to an object of type FirstViewController, but it is declared in a class of type SecondViewController.
Related
I'm working on an app with a Split View controller and would like to store the main data class in the App Delegate so I can access it from multiple views (MasterView, DetailView, and several PopUps).
I'm a bit of a noob and can't figure out why Im getting the error:
AppDelegate.m:31:26: Property 'dataController' not found on object of type 'MasterViewController'
Below is the relevant code - any help is much appreciated. Thanks.
AppDelegate.h
#import <UIKit/UIKit.h>
#class EventClassDataController;
#class MasterViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
AppDelegate.m
#import <UIKit/UIKit.h>
#class EventClassDataController;
#class MasterViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
MasterViewController.h
#import <UIKit/UIKit.h>
#class DetailViewController;
#class EventClassDataController;
#interface MasterViewController : UITableViewController
#property (strong, nonatomic) EventClassDataController *dataController;
#property (strong, nonatomic) DetailViewController *detailViewController;
#end
MasterViewController.m
#import "MasterViewController.h"
#import "DetailViewController.h"
#import "EventClassDataController.h"
#import "EventClass.h"
#interface MasterViewController ()
#end
#implementation MasterViewController
#synthesize detailViewController, dataController;
- (void)awakeFromNib
{
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
[super awakeFromNib];
// Initialize event data
self.dataController = [[EventClassDataController alloc] init];
}
EventClassDataController.h
#import <Foundation/Foundation.h>
#class EventClass;
#interface EventClassDataController : NSObject
#property (nonatomic, copy) NSMutableArray *masterEventList;
-(NSUInteger)countOfList;
-(EventClass *)objectInListAtIndex:(NSUInteger)theIndex;
-(void)addNewEvent:(EventClass *)event;
-(void)removeEvent:(EventClass *)event;
#end
You need to add
#import "MasterViewController.h"
to AppDelegate.m.
Explantation:
From your error message I can tell that you're trying to access a property of MasterViewController on line 26 of your AppDelegate. However, in your AppDelegate class you only have a forward declaration ("#class MasterViewController") and you don't include the actual header file for MasterViewController. What this means is that AppDelegate knows there exists a class named MasterViewController somewhere in your project... but that's all it knows. AppDelegate doesn't know anything about the contents of MasterViewController, i.e. properties or methods MasterViewController declares.
The reason to use #class in a header file is so that you can have properties in an #interface such as
#property (nonatomic, strong) MasterViewController * appDelegatesReferenceToMasterViewController;
without having to import MasterViewController.h in AppDelegate.h. This way, other files in your project can import AppDelegate.h without also inadvertently importing MasterViewController.h.
Translation:
You writing the code:
#class MasterViewController;
is like saying to the compiler:
Yo... compiler. I'm going to be talking about something called MasterViewController in this header file and you don't know what a MasterViewController is... but don't trip out bro. It's all good.
But then, later in the .m file after you write the code:
... masterViewController.dataController ...
the compiler responds:
Whoa, whoa, whoa. I was cool with you just having a variable with the type MasterViewController in the header file because you told me it was all good and not to worry. But now here you are trying to use some aspect of MasterViewController that I know nothing about. How am I supposed to know if this is legal or not? Not cool bro.
I'm trying to synthesise my NSWindow "loginscreen" but I keep getting the error "property implementation must have its declaration in interface "appdelegate"
This is the part of the header
#interface AppDelegate : NSObject <NSApplicationDelegate>
{
#private
NSWindow *window;
NSWindow *loginscreen;
And this my method:
#synthesize loginscreen = _loginscreen;
Any suggestions? thanks for the help.
If you are using ARC you need to add the following line to your AppDelegate.h file:
#property (nonatomic, strong) NSWindow *loginWindow;
If you are not using ARC you should instead use:
#property (nonatomic, assign) NSWindow *loginWindow;
This line would go after the {} block in #interface but before the #end.
I have the following code:
//RootViewController.h:
#import <UIKit/UIKit.h>
#interface RootViewController : UIViewController{
IBOutlet UITextField *login_uname;
IBOutlet UITextField *login_pword;
IBOutlet UIActivityIndicatorView *login_thinger;
IBOutlet UIImageView *logo;
IBOutlet UISwitch *login_remember;
IBOutlet UIScrollView *scrollView;
}
-(IBAction) login_submitClick:(id)sender;
-(IBAction) doneEditing:(id)sender;
-(IBAction) clearPword:(id)sender;
-(void) showSignUp:(id)sender;
-(void)doLogout:(id)sender;
//for file handling:
-(NSString *)documentsPath;
-(NSString *)readFromFile:(NSString *)filePath;
-(void) writeToFile:(NSString *)text withFileName:(NSString *) filePath;
#end
//RootViewController.m
#import "RootViewController.h"
//#import "Main.h"
//#import "SignUp.h"
#import "ASIHTTPRequest.h"
#import "ASIFormDataRequest.h"
#import "CommonCrypto/CommonHMAC.h"
#import "Details.h"
//#import "signUpSMS.h"
#import "JSON.h"
#implementation PrestoCab3ViewController
#synthesize login_uname; //this line throws the error in the title
...
I'm using XCode 4.1 and was wondering if someone could please help me get to the bottom of this error. I'm very new to XCode.
Many thanks in advance,
You need to declare the property with #property in your interface.
#property( nonatomic, retain ) IBOutlet UITextField * login_uname;
Here, non-atomic is used because it's an IBOutlet.
Also note the property has the retain modifier, meaning you are responsible to release the object when you don't need it anymore.
What am I doing wrong? This is the .h file:
#import <UIKit/UIKit.h>
#import <sqlite3.h>
#class ReaderViewController;
#interface ReaderAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
ReaderViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet ReaderViewController *viewController;
- (void)checkForDatabase;
//- (void)SQLiteConnection: (NSString *)defaultDBPath;
#end
The error is shown here:
You are calling the [self checkForDatabase] method which doesn't appear to exist in the .m file.
The Incomplete Implementation warning is because you have declared the checkForDatabase method in your interface
The Method Definition error is because you are attempting to call the missing method in the application:didFinishLaunchingWithOptions: method.
You have failed to implement checkForDatabase in ReaderAppDelegate.m (or in any other file you're linking into the project). You said you would in the header, and then you didn't.
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
Going a bit crazy with the #synthesizes, 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
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.)