我的程序中有 2 个类,第一类是 class1,第二类是 class2。我想在类 1 中创建和初始化全局变量并在类 2 中使用,但编译器给了我这个错误 XD:
Undefined symbols for architecture i386:
"_saeid", referenced from:
-[class2 viewDidLoad] in class2.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我在 class1 中创建全局变量并以这种方式在 class2 中运行它,但不起作用:
类1.h
extern int saeid; // this is global variable
@interface class1 : UITableViewController<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) IBOutlet UITableView *table;
@end
类1.m
#import "class1.h"
#import "class2.h"
@implementation class1
{
int saeid;
}
@synthesize table;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int x = (indexPath.row)+1;
saeid = x; //initialize global variable
NSLog(@"X & SAEID: %d & %d",x,saeid);
}
类2.h
#import "class1.h"
@interface class2 : UIViewController<UIScrollViewDelegate>
{
}
@end
类2.m
#import "class2.h"
@implementation class2
{
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Saeid in class2 : %d",saeid);
}