开发者

compilation problem on device not on simulator

开发者 https://www.devze.com 2023-03-26 09:11 出处:网络
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

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              ///
CGP开发者_运维问答oint                     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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消