无法使用viewWithTag访问NSSearchField

时间:2011-11-24 14:22:44

标签: macos cocoa tags nssearchfield

我在appcontroller.m类中创建了searchfield,并将其作为子视图添加到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];
}

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

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

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

0 个答案:

没有答案