设备上的编译问题不在模拟器上

时间:2011-08-05 16:18:39

标签: ios ipad compilation base-class

还有一些重构(为两个不同的类编写基类+其他一些东西),我的项目无法在ipad上编译,在模拟器上运行不正常

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

当然,这些变量被声明(在新的基类中),并且2个类来自基类

任何想法为什么?我也导入了基类。

发生错误的类:

#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;

}

基类:

@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;


}

无法编译的语句:

    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

如果我在每个变量之前添加self,问题似乎消失了,例如:self.width = 1024,但我不想这样做(有很多东西要改变)

1 个答案:

答案 0 :(得分:0)

编辑:

从你上次的评论中看来,你似乎缺少首先定义这些变量:

NSInteger width       = [PaintMenuViewController width];
...

如果这不正确,请在代码中添加更多上下文,否则将无法理解......

老答案:

在声明中:

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

您正试图错误地访问ivars。

您应该在可以访问其ivars(成员变量)之前分配和初始化一个类。

目前尚不清楚此代码的来源(我的意思是来自哪个类/方法)。如果它位于其中一个视图控制器中,您只需执行以下操作:

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

否则,请指定代码上下文(类/方法)。

如果你需要类方法(即你可以在分配它们之前自己调用类的方法),你可以定义:

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

这些方法可以返回您需要的值。