PDA

View Full Version : New problem: method def. not in @implementation context




begdev
Jun 18, 2009, 06:42 PM
If you've seen me here before, I've been quite noob.
But like i promised, i read up and am making an RSS organizer application all my, myself. but i ran into some issues... After debugging, I am left with 1 error (twice)

EDIT: After some tinkering i discovered by first problem, but now i have new ones...
"fatal error: method definition not in @implementation context"

heres the code...
my header:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface NavController : UINavigationController {

IBOutlet id delegate;

UIView *infoView;

UIView *settingsView;

}

@end

- (IBAction)infoClick:(id)sender;
- (IBAction)settingsClick:(id)sender;



my implementation:
#import "Navcontroller.h"
@class infoView
@implementation Navcontroller
@end

- (IBAction)infoClick:(id)sender {

[self addSubView:infoView];

}

- (IBAction)settingsClick:(id)sender {

}



kainjow
Jun 18, 2009, 08:51 PM
The @end is at the wrong place. Move it to the bottom of both files. All method declarations and implementations should be between the @interface/@end and @implementation/@end.

The '@class infoView' line should be removed.

'@implementation Navcontroller' should be '@implementation NavController' - Objective-C is case sensitive.

begdev
Jun 18, 2009, 09:04 PM
The @end is at the wrong place. Move it to the bottom of both files. All method declarations and implementations should be between the @interface/@end and @implementation/@end.

The '@class infoView' line should be removed.

'@implementation Navcontroller' should be '@implementation NavController' - Objective-C is case sensitive.

Works!

except now we have a few more issues...

Navcontroller.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface NavController : UINavigationController {

IBOutlet id delegate;

UIView *infoView;

UIView *settingsView;

}

- (IBAction)infoClick:(id)sender;
- (IBAction)settingsClick:(id)sender;

@end

Navcontroller.m

http://www.grabup.com/uploads/83193db5ac361eac3da1f50c99d26c57.png

infoView.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface infoView : UIView {

}


- (IBAction)backButton:(id)sender;

@end

infoView.m

#import "infoView.h"

@implementation infoView

- (IBAction)backButton:(id)sender {

[self removeFromSuperview];
}

@end

i took out the @class in all files. and i think this has caused the issue, but i can't get it to compile with them...

basically, on the navigation bar, there is a button, and its linked to when its clicked, add the infoView to it...

kainjow
Jun 18, 2009, 09:11 PM
To compile that'd be [self.view addSubview:infoView] but I have a feeling that's not what you want..

But, infoView is never set. I see that you have some C++ experience. ALL objects in Cocoa are used as pointers, so you cannot just declare it and have it created like you can when you declare an object in C++. You need to assign it to something. Is your infoView in a nib? Maybe you could post a screenshot of your nib.

begdev
Jun 18, 2009, 09:14 PM
To compile that'd be [self.view addSubview:infoView] but I have a feeling that's not what you want..

But, infoView is never set. I see that you have some C++ experience. ALL objects in Cocoa are used as pointers, so you cannot just declare it and have it created like you can when you declare an object in C++. You need to assign it to something. Is your infoView in a nib? Maybe you could post a screenshot of your nib.

sure hold on for the screenshot. thx for your help btw.

EDIT: k here it is http://www.grabup.com/uploads/aae857bd8ae20979f40f4e8f861c0ca6.png

kainjow
Jun 18, 2009, 09:18 PM
Ok, declare your infoView as an IBOutlet like you did with delegate and then you can connect it from the controller to the view in the nib.

begdev
Jun 18, 2009, 09:23 PM
Ok, declare your infoView as an IBOutlet like you did with delegate and then you can connect it from the controller to the view in the nib.

like this?

.h

http://www.grabup.com/uploads/cd9fb66c6c70393f566387d3400d1eab.png

.m

http://www.grabup.com/uploads/fea58f1e8bbf24563e986cca4995bf6a.png



http://www.grabup.com/uploads/c4908e347c913d24089b355bb3d6ac88.png

amazingly enough, i got the other 70% of the app done perfectly (its the tableview part)

kainjow
Jun 18, 2009, 09:25 PM
UINavigationController already has a property for delegate, so remove that entirely.

For the infoView, it's preferred to declare it like IBOutlet UIView *infoView; so that IB knows what it really is and prevents you from connecting it to something else.

I gave you the fix above for the addSubview: method (remember Obj-C is case sensitive) - the other one should be obvious. Just delete or comment out the settingsClick: method definition if you're not going to use/implement it.

Edit: I should just get on iChat, share screens and fix it all for you real quick :p

begdev
Jun 18, 2009, 09:30 PM
UINavigationController already has a property for delegate, so remove that entirely.

For the infoView, it's preferred to declare it like IBOutlet UIView *infoView; so that IB knows what it really is and prevents you from connecting it to something else.

I gave you the fix above for the addSubview: method - the other one should be obvious. Just delete or comment out the settingsClick: method definition if you're not going to use/implement it.

Ok well i did all of that, and it makes sense on how this would work. Yet, it does not... When I click the Nav button, it crashes.

Could this be that I'm using the navbar controller and nav button? and then a UIView?


Edit: I should just get on iChat, share screens and fix it all for you real quick :p


Would you???

MacMatt1
Feb 2, 2010, 07:59 AM
I have a similar problem and after exhausting attempts can not rearrange this into a way that will compile. Could somebody offer me some kind help please. Will be much appreciated.



#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface FestViewController : UIViewController {
IBOutlet UILabel *holidayInfo;
IBOutlet UILabel *holidayWeb;
IBOutlet UIImageView *holidayImage;
IBOutlet UILabel *holidayDays;
IBOutlet UILabel *holidayLoc;
IBOutlet UILabel *holidayLong;
IBOutlet UILabel *holidayLat;
IBOutlet UILabel *holidayID;
IBOutlet UILabel *holidayDates;
IBOutlet UILabel *holidayCount;

}
@end



@interface AddressAnnotation : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;

NSString *mTitle;
NSString *mSubTitle;
}

@end

@interface MapViewController : UIViewController<MKMapViewDelegate> {

IBOutlet UIButton *goButton;
IBOutlet MKMapView *mapView;

AddressAnnotation *addAnnotation;
}

- (IBAction) showAddress;

-(CLLocationCoordinate2D) addressLocation;

@end

@property (nonatomic, retain) IBOutlet UILabel *holidayInfo;
@property (nonatomic, retain) IBOutlet UILabel *holidayWeb;
@property (nonatomic, retain) IBOutlet UIImageView *holidayImage;
@property (nonatomic, retain) IBOutlet UILabel *holidayDays;
@property (nonatomic, retain) IBOutlet UILabel *holidayLoc;
@property (nonatomic, retain) IBOutlet UILabel *holidayLong;
@property (nonatomic, retain) IBOutlet UILabel *holidayLat;
@property (nonatomic, retain) IBOutlet UILabel *holidayID;
@property (nonatomic, retain) IBOutlet UILabel *holidayDates;
@property (nonatomic, retain) IBOutlet UILabel *holidayCount;



- (IBAction)webPush:(id)sender;

Luke Redpath
Feb 2, 2010, 08:58 AM
You have your @end above all of your @property declarations. The @end statement should be the last thing in your interface declaration.

MacMatt1
Feb 3, 2010, 11:45 AM
Hi again thanks for that, it now compiles. Next problem is though that it crashes when that view is loaded. There is a warning about the @end. I'll attach a screenshot. Thanks in advance again!

Luke Redpath
Feb 3, 2010, 03:39 PM
The previous @implementation block has no @end.

Might be worth going back and re-reading the Objective-C basics again. This is really basic stuff.

dejo
Feb 3, 2010, 04:27 PM
Also, to keep things less confusing, it's common to restrict one class definition per file (with paired .h and .m, of course). So, you'd have:
- FestViewController.h and .m
- AddressAnnotation.h and .m
- MapViewController.h and .m