我试图将 NSString
设置为 ClassB 的 NSTextField
,其中在 ClassA 中调用该方法。但是 NSTextField
没有初始化 NSString
的值。
classB.h
NSString *folderPath;
B类.m
- (id)initWithWindow:(NSWindow *)window
{
self = [super initWithWindow:window];
if (self) {
[alertWindow setIsVisible:NO];
[pdfStatusText setStringValue:@"Null"];
}
return self;
}
-(id)initWithAlertWindowControllers:(NSString*)fileName andTitle:(NSString *)title
{
//some part of code here
//i am trying to set String value to the NSTextField pdfStatusText
folderPath=fileName;
[pdfStatusText setStringValue:folderPath];
}
- (void)windowDidLoad
{
[super windowDidLoad];
[self.window makeKeyAndOrderFront:self];
}
A.m级
_alertWindow = [[AlertWindowController alloc] initWithAlertWindowControllers:Path andTitle:@"Project"];
谢谢你..
最佳答案
你的代码应该可以工作,尝试将 NSlog 写入你的方法中,并确定你的方法是否有效,然后你的问题可能是因为你的 textField -(id)initWithAlertWindowControllers:(NSString*)fileName andTitle:(NSString *)title
{
NSLog(@"Is it working?");<br/>
//some part of code here
//i am trying to set String value to the NSTextField pdfStatusText
folderPath=fileName;<br/>
pdfStatusText.Text=title;
}
也许你应该尝试类似 pdfStatusText.delegate=self
的东西;在你看来确实加载了方法。
关于objective-c - 访问 Objective C 中其他类的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19264334/