我在 Obj-C 中从事一个项目,其中我有一个基类(ViewController)和一个派生类(MultiPlayer)。
现在我已经在基类中声明了某些变量和属性。
我的属性正在从派生类访问,但我无法访问变量(int、char 和 bool 类型)。
我对 Obj-C 完全陌生,所以我不知道出了什么问题。
我使用了 C 和 C++ 中使用的数据类型。
在 Obj-C 中是否有一些特定的方法来声明变量?
如果是这样,如何?
这是我的文件
视图控制器.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak,nonatomic) IBOutlet UIImageView* backGroungImage;
@property (strong,nonatomic) IBOutlet UIImageView *blockView1;
@property (strong,nonatomic) IBOutlet UIImageView *blockView2;
@property (strong,nonatomic) IBOutlet UIImageView *blockView3;
@property (strong,nonatomic) IBOutlet UIImageView *blockView4;
@property (strong,nonatomic) IBOutlet UIImageView *blockView5;
@property (strong,nonatomic) IBOutlet UIImageView *blockView6;
@property (strong,nonatomic) IBOutlet UIImageView *blockView7;
@property (strong,nonatomic) IBOutlet UIImageView *blockView8;
@property (strong,nonatomic) IBOutlet UIImageView *blockView9;
@property (strong,nonatomic) UIImage *x;
@property (strong,nonatomic) UIImage *O;
@property (strong,nonatomic) IBOutlet UIImageView* back1;
@property (strong,nonatomic) IBOutlet UIImageView* back2;
@end
视图控制器.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
int chooseTheBackground = 0;
int movesToDecideXorO = 0;
int winningArrayX[3];
int winningArrayO[3];
int blocksTotal[9] = {8,3,4,1,5,9,6,7,2};
int checkIfContentInBlocks[9] = {0,0,0,0,0,0,0,0,0};
char determineContentInBlocks[9] = {' ',' ',' ',' ',' ',' ',' ',' ',' '};
bool player1Win = false;
bool player2Win = false;
bool playerWin = false;
bool computerWin = false;
- (void)viewDidLoad
{
[super viewDidLoad];
if(chooseTheBackground==0)
{
UIImage* backImage = [UIImage imageNamed:@"MainBack1.png"];
_backGroungImage.image=backImage;
}
if(chooseTheBackground==1)
{
UIImage* backImage = [UIImage imageNamed:@"MainBack2.png"];
_backGroungImage.image=backImage;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我无法在派生类中使用上述声明的变量!