New problem: method def. not in @implementation context

Discussion in 'iOS Programming' started by begdev, Jun 18, 2009.

  1. begdev macrumors newbie

    Joined:
    Mar 14, 2009
    #1
    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:
    Code:
    #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:
    Code:
    #import "Navcontroller.h"
    @class infoView
    @implementation Navcontroller
    @end
    
    - (IBAction)infoClick:(id)sender {
    	
    	[self addSubView:infoView];
        
    }
    
    - (IBAction)settingsClick:(id)sender {
        
    }
    
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    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.
     
  3. begdev thread starter macrumors newbie

    Joined:
    Mar 14, 2009
    #3
    Works!

    except now we have a few more issues...

    Navcontroller.h
    Code:
    #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

    [​IMG]

    infoView.h

    Code:
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    
    @interface infoView : UIView {
    
    }
    
    
    - (IBAction)backButton:(id)sender;
    	
    @end
    infoView.m

    Code:
    #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...
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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.
     
  5. begdev thread starter macrumors newbie

    Joined:
    Mar 14, 2009
    #5
    sure hold on for the screenshot. thx for your help btw.

    EDIT: k here it is http://www.grabup.com/uploads/aae857bd8ae20979f40f4e8f861c0ca6.png
     
  6. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    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.
     
  7. begdev thread starter macrumors newbie

    Joined:
    Mar 14, 2009
    #7
    like this?

    .h

    [​IMG]

    .m

    [​IMG]



    [​IMG]

    amazingly enough, i got the other 70% of the app done perfectly (its the tableview part)
     
  8. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #8
    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
     
  9. begdev thread starter macrumors newbie

    Joined:
    Mar 14, 2009
    #9
    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?


    Would you???
     
  10. MacMatt1 macrumors newbie

    Joined:
    Feb 2, 2010
    #10
    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.

    Code:
    
    #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;
    
     
  11. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #11
    You have your @end above all of your @property declarations. The @end statement should be the last thing in your interface declaration.
     
  12. MacMatt1 macrumors newbie

    Joined:
    Feb 2, 2010
    #12
    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!
     

    Attached Files:

  13. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #13
    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.
     
  14. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #14
    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
     

Share This Page