设备上而非模拟器上的编译问题

发布于 2024-11-28 09:35:24 字数 2221 浏览 0 评论 0原文

和一些重构(为两个不同的类编写一个基类+一些其他东西),我的项目无法在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无畏 2024-12-05 09:35:24

编辑:

从您最后的评论来看,您似乎首先缺少定义这些变量:

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文