无法使用 viewWithTag 访问 NSSearchField

发布于 2024-12-17 20:29:02 字数 1091 浏览 1 评论 0原文

我正在我的 appcontroller.m 类中创建搜索字段,并将其作为子视图添加到 awakeFromNib 中的 BrowserView

    mysearchField = [ [ NSSearchField alloc ] initWithFrame: NSMakeRect(10 , 50.0, 225.0, 35.0) ];

    [mysearchField setTag:2];

    [[mysearchField cell] setPlaceholderString:@"Page Number & Press Enter"];
    [BrowserView addSubview: mysearchField ];

    [mysearchField release];


-(NSView *)fullBrowserView
{
    NSLog(@"fullBrowserView called");
    return fullBrowserView;
}

当我尝试从不同的 nsview 子类访问此搜索字段时

-(BOOL)becomeFirstResponder {

    appController *pAppController = [[appController alloc] init];
    //[pIKBController testMethod];
    NSSearchField *mySearchFieldTemp =(NSSearchField *) [[pAppController fullBrowserView]  viewWithTag:2];
    [mySearchFieldTemp setStringValue:@""];

    [pAppController release];
    return [super becomeFirstResponder];
}

,fullBrowserView 被 [pAppController fullBrowserView] 调用,但我的 NSSearchField 没有重置为零值。

注意:fullBrowserView 是 IBOutlet 并在 Xib 文件(Interface Builder)中创建,

可能是什么问题。请帮忙。

I am creating the searchfield in my appcontroller.m class and adding it as subview to BrowserView in awakeFromNib

    mysearchField = [ [ NSSearchField alloc ] initWithFrame: NSMakeRect(10 , 50.0, 225.0, 35.0) ];

    [mysearchField setTag:2];

    [[mysearchField cell] setPlaceholderString:@"Page Number & Press Enter"];
    [BrowserView addSubview: mysearchField ];

    [mysearchField release];


-(NSView *)fullBrowserView
{
    NSLog(@"fullBrowserView called");
    return fullBrowserView;
}

When I am trying to accessing this searchfield from a different nsview sub class

-(BOOL)becomeFirstResponder {

    appController *pAppController = [[appController alloc] init];
    //[pIKBController testMethod];
    NSSearchField *mySearchFieldTemp =(NSSearchField *) [[pAppController fullBrowserView]  viewWithTag:2];
    [mySearchFieldTemp setStringValue:@""];

    [pAppController release];
    return [super becomeFirstResponder];
}

fullBrowserView is getting called with [pAppController fullBrowserView],but my NSSearchField is not resetting to nil value.

Note : fullBrowserView is IBOutlet and created in the Xib file(Interface Builder)

What might be the problem.Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文