gpt4 book ai didi

ios - 在我的函数中使用未声明的标识符

转载 作者:行者123 更新时间:2023-11-28 22:16:07 27 4
gpt4 key购买 nike

我正在使用未声明的标识符,即使我在 .h 中声明它并在 .m 中合成。

我之前遇到过另一个问题,但我在堆栈溢出中发布了一个问题,他们说我不应该将它们排除在外,当我将它们排除在外时,代码给了我一个错误“ld: symbol(s) not found for architecture i386clang: error: linker command failed with exit code 1 (use -v to see invocation)”并且知道我没有,它给了我“使用未声明的标识符”,如你所见

.h

#import <UIKit/UIKit.h>

BOOL OFrameIsHidden, XFrameIsHidden;
NSString *topOne, *topTwo, *topThree;
NSString *midOne, *midTwo, *midThree;
NSString *botOne, *botTwo, *botThree;

void hideAll(void);

@interface ViewController : UIViewController
void hideAll(void);
@property (weak, nonatomic) IBOutlet UIImageView *XFrame;
@property (weak, nonatomic) IBOutlet UIImageView *OFrame;
@property (weak, nonatomic) IBOutlet UIImageView *frame;
@property (weak, nonatomic) IBOutlet UILabel *X;
@property (weak, nonatomic) IBOutlet UILabel *O;
@property (weak, nonatomic) IBOutlet UILabel *WhoWon;



@property (weak, nonatomic) IBOutlet UIButton *oneOne;
@property (weak, nonatomic) IBOutlet UIButton *oneTwo;
@property (weak, nonatomic) IBOutlet UIButton *oneThree;
@property (weak, nonatomic) IBOutlet UIButton *twoOne;
@property (weak, nonatomic) IBOutlet UIButton *twoTwo;
@property (weak, nonatomic) IBOutlet UIButton *twoThree;
@property (weak, nonatomic) IBOutlet UIButton *threeOne;
@property (weak, nonatomic) IBOutlet UIButton *threeTwo;
@property (weak, nonatomic) IBOutlet UIButton *threeThree;

@end

.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize XFrame, OFrame, frame, X, O, WhoWon;
@synthesize oneOne, oneTwo, oneThree;
@synthesize twoOne, twoTwo, twoThree;
@synthesize threeOne, threeTwo, threeThree;

void hideAll(void){

[OFrame setHidden:YES];
[XFrame setHidden:YES];
[frame setHidden:YES];

[X setHidden:YES];
[O setHidden:YES];


[oneOne setHidden:YES];
[oneTwo setHidden:YES];
[oneThree setHidden:YES];

[oneOne setHidden:YES];
[twoTwo setHidden:YES];
[twoThree setHidden:YES];

[threeOne setHidden:YES];
[threeTwo setHidden:YES];
[threeThree setHidden:YES];
}

供您引用,IBAcions 有更多代码,但我不想写这么长。

最佳答案

不要像这样混合使用函数和方法。它并没有真正帮助您,您所做的只是造成可见性问题。

方法通过传递一个隐藏参数来工作,该参数允许访问 self。您的所有 @property 定义都是实例变量,因此您需要访问 self 才能访问它们。函数,例如您的 hideAll,没有这种访问权限,因此它们无法访问实例变量(它们不知道实例是什么)。

您通常也不希望在类定义之外定义变量。

将您的变量带入类中或将它们移动到另一个更合适的类中,并为您的代码使用方法,而不是函数。

关于ios - 在我的函数中使用未声明的标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21628889/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com