【发布时间】:2013-04-07 08:03:27
【问题描述】:
我的程序中有 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 中运行它,但不起作用:
class1.h
extern int saeid; // this is global variable
@interface class1 : UITableViewController<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) IBOutlet UITableView *table;
@end
class1.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);
}
class2.h
#import "class1.h"
@interface class2 : UIViewController<UIScrollViewDelegate>
{
}
@end
class2.m
#import "class2.h"
@implementation class2
{
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Saeid in class2 : %d",saeid);
}
【问题讨论】:
标签: ios objective-c global-variables