0

And some refactoring (writing a base class for two distinct classes + a few other things) , my project failed to compile on ipad , not works fine on simulator

/Users/.../PaintViewController.m:50: error: 'width' undeclared (first use in this function)
/Users/.../PaintViewController.m:59: error: 'backgroundView' undeclared (first use in this function)

of course, these variables are declared (in the new base class) , and the 2 classes inherets from the base class

any ideas why ? I imported the base class as well.

class where the errors takes place:

#import "PaintViewControllerBase.h"

@class PopupSaveDrawingController;


@interface PaintViewController : PaintViewControllerBase
{

MenuBarViewController       *menuBarView;

bool                        bBarIsOpened;    
bool                        bIsClosing;
bool                        bIsOpening;
float                       fBarY;

NSTimer                     *toggleTimer;

NSArray                     *toolBrushImgArray;// liste des textures de brosses    

PopupSaveDrawingController  *popupSaveDrawning;

}

base class:

@interface PaintViewControllerBase : UIViewController
{
// Handle Move              ///
CGPoint                     location;
CGPoint                     previousLocation;
BOOL                        firstTouch;

// Size                     ///
NSInteger                   width;
NSInteger                   height;

// Actions

UndoRedoManager             *undoManager;

toolType                    currentToolType;

// Brush
PaintBrush                  *brush;
PaintImage                  *image;

// image buffer             //////
NSMutableData               *data;

// GUI
PaintCanvas                 *backgroundView;
PaintCanvas                 *modeleView;
PaintCanvas                 *drawView;


}

statement that failed to compile :

    width       = [PaintMenuViewController width]; // error here on ipad target only
    height      = [PaintMenuViewController height];// error here on ipad target only
    CGRect rect = CGRectMake(0,0,width,height);
    self.view   = [[UIView alloc] initWithFrame:rect];


    /**********************
     * IMAGEVIEW BACKGROUND
     **********************/
    backgroundView = [[PaintCanvas alloc] initWithFrame:rect]; // error here on ipad target only

the problem seems to disapear if I add self before each variable eg : self.width = 1024, but I would prefer not to do this (there is a lot of stuff to change)

Nico AD
  • 1,657
  • 4
  • 31
  • 51

1 Answers1

0

EDIT:

from your last comment it seems that you are missing defining those variables in the first place:

NSInteger width       = [PaintMenuViewController width];
...

If this is not correct, please add more context to your code, otherwise it will be impossible to understand...

OLD ANSWER:

In the statements:

width       = [PaintMenuViewController width]; // error here on ipad target only
height      = [PaintMenuViewController height];// error here on ipad target only

you are trying to access ivars incorrectly.

You are supposed to allocate and initialize a class before you can access its ivars (member variables).

It is not clear where this code come from (from which class/method, I mean). If it is in one of the view controllers themselves, you simply do:

width       = [self width]; 
height      = [self height];

otherwise, please, specify the code context (class/method).

If you need class methods (i.e., methods that you can call on the class themselves, before allocating them), you can define:

 @interface PaintViewControllerBase : UIViewController {
 }
 +(NSInteger)width;
 +(NSInteger)height;
 ...
 @end

those methods could return the values you need.

sergio
  • 68,819
  • 11
  • 102
  • 123
  • this variables are const +(const NSInteger) width; +(const NSInteger) height – Nico AD Aug 05 '11 at 16:32
  • I know, but the point is: they are normal class variables (ivars), you need an object (your controller) to access them. See also my next edit... – sergio Aug 05 '11 at 16:34
  • and the problem is the same if I write width = 1024; height = 768; – Nico AD Aug 05 '11 at 16:34
  • the problem seems to disapear if I add self before each variable eg : self.width = 1024, but I would prefer not to do this (there is a lot of stuff to change) – Nico AD Aug 05 '11 at 16:46
  • could you explain what those variables are for and where this method is located? – sergio Aug 05 '11 at 16:47
  • In another class, but forget about width/height , I get like 70 compile errors , even if I comment the width/height initialisation – Nico AD Aug 05 '11 at 20:12
  • Maybe related to http://stackoverflow.com/questions/2778405/not-so-silly-objective-c-inheritance-problem-when-using-property-gcc-bug – Nico AD Aug 06 '11 at 08:46