访问任何类中的全局变量

时间:2010-02-26 09:29:31

标签: iphone objective-c xcode

嘿,我一直在试图弄清楚为什么我会收到这个警告:

  

'TxtAppDelegate'可能无法响应'-TCN'   'TxtAppDelegate'可能无法响应'-TID'

当我尝试使用此代码时:

// .h file
@interface RootViewController : UITableViewController <UIActionSheetDelegate> {
NSString *theCompanyName;
NSString *theID;
}

@property (nonatomic, retain)NSString *theCompanyName;
@property (nonatomic, retain)NSString *theID;

// .m
NSString *theCompanyName;
NSString *theID;

@synthesize theCompanyName;
@synthesize theID;

TxtAppDelegate *customObjInstance = [[TxtAppDelegate alloc] init];

theCompanyName = [customObjInstance TCN];
theID = [customObjInstance TID];

我添加了.h文件的标题,其中包含两个函数。代码有效,但我真的想解决警告问题。

任何帮助都可以很好地解决我的这个问题:)

大卫

2 个答案:

答案 0 :(得分:2)

虽然看到声明TxtAppDelegate的头文件会更有帮助,但我猜测方法声明必须关闭。他们应该是这样的:

- (NSString *)TCN;
- (NSString *)TID;

如果这不是问题的原因,请在此处发布头文件,以便我们检查它。

答案 1 :(得分:0)

如何在标题中声明这两个函数?

它们应属于TxtAppDelegate类或协议的类别。如果选择协议,TxtAppDelegate接口应该提到它符合该协议。