设备上而非模拟器上的编译问题
和一些重构(为两个不同的类编写一个基类+一些其他东西),我的项目无法在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,但我不想这样做(有很多要改变的东西)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:
从您最后的评论来看,您似乎首先缺少定义这些变量:
如果这不正确,请在您的代码中添加更多上下文,否则将无法理解...
旧答案:
在语句中:
您正在尝试错误地访问 ivars。
您应该先分配并初始化一个类,然后才能访问它的 ivars(成员变量)。
目前尚不清楚这段代码来自哪里(我的意思是来自哪个类/方法)。如果它位于视图控制器本身之一中,您只需这样做:
否则,请指定代码上下文(类/方法)。
如果您需要类方法(即,在分配它们之前可以在类本身上调用的方法),您可以定义:
这些方法可以返回您需要的值。
EDIT:
from your last comment it seems that you are missing defining those variables in the first place:
If this is not correct, please add more context to your code, otherwise it will be impossible to understand...
OLD ANSWER:
In the statements:
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:
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:
those methods could return the values you need.