开发者

Trouble initializing NSViewController - UI Objects not retained

I'm having some issues with understanding how to work with NSViewControllers on Mac. I'm trying to create custom table cells for NSTableView. In one of the delegates of the NSTableView, it can return a view, instead of a cell.

I have a subclass of NSViewController, and in the .xib everything is linked up correctly, but when I initialize the NSViewController, its UI components is not initialized... not even the default view that comes with it. I have tr开发者_C百科ied it with a clean, stock, untouched implementation of NSViewController, just to make sure that the issue is not with something I'm doing. It is probably. I am initializing the NSViewController as follows:

testview *tmpChannel = [[testview alloc] initWithNibName:@"testview" bundle:nil];

The .xib does exist, and all the outlets are linked up correctly. Could anyone explain what is happening here? I'm using xCode 4.1 with Lion OS

Thanks.


Check your initialization with

NSLog(@"%@", [tmpChannel description]);

From your code I would assume, that you do get an object address here. That means the error is probably in the code that is supposed to display it.

BTW, I recommend using capitalized class names, such as TestView.

EDIT:

Additional Information for loading xibs: The name of the xib file has to be the exact same as the class name. In this case you can actually completely omit the initWithNibName:bundle: part:

// xib file is "ViewController.xib"
// Class is defined as "ViewController"

ViewController *newController = [[ViewController alloc] init];  // this is enough


The IB (xib) Objects are initialized only after the view is actually loaded. And not during the initWithNibName:bundle:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜