objective-c - 访问 Objective C 中其他类的对象?

标签 objective-c cocoa

我试图将 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/

相关文章:

objective-c - 在 IOS 5.0 中创建可扩展 TableView

objective-c - 处理 NSStatusItem 上的 onMouseOver 和 onMouseOut

cocoa - 自定义 NSAnimationCurve

ios - CellForRowAtIndexPath 中给出的 UIButton 标记仅给出自定义 UITableViewCell 中的最后一个标记值

objective-c - ASIHTTPRequest 禁用缓存

objective-c - NSWindow setFrame | NSWindow设置屏幕上的位置

iphone - CoreData内存管理问题

iOS:NSFetchedResultsController、ControllerDidChangeContent 重新排序后执行两次

objective-c - 如何忽略屏幕上多余的手指?

iOS - ALAssetsGroupPropertyName 返回空专辑名称