Skip to content
This repository has been archived by the owner on Nov 1, 2017. It is now read-only.

TUIViewNSViewContainer doesn't work as expected #70

Closed
luosheng opened this issue Sep 13, 2012 · 1 comment
Closed

TUIViewNSViewContainer doesn't work as expected #70

luosheng opened this issue Sep 13, 2012 · 1 comment
Labels

Comments

@luosheng
Copy link

Here's the scenario: I have a TUIView called ExampleView acting as the rootView of a TUINSView and I want to add an NSView to it. So I copy the following code from TwUI's ExampleProject and paste it to ExampleView's initWithFrame: method.

NSTextField *textField = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 180, 91, 22)];
[textField.cell setUsesSingleLineMode:YES];
[textField.cell setScrollable:YES];

self.textFieldContainer = [[TUIViewNSViewContainer alloc] initWithNSView:textField];
self.textFieldContainer.backgroundColor = [NSColor blueColor];
[self addSubview:self.textFieldContainer];

It was supposed to show a text field on the screen. However it just showed a blue rectangle instead (the TUIViewNSViewContainer).

So I looked into the source of TUIViewNSViewContainer. It tried to add the NSView to its ancestorTUINSView's appKitHostView. However, at that time the TUIViewNSViewContainer's ancestorTUINSView property is still nil becasuse here's how we initialize the ExampleView in the ExampleAppDelegate:

TUINSView *tuiTableViewContainer = [[TUINSView alloc] initWithFrame:b];
[tableViewWindow setContentView:tuiTableViewContainer];

ExampleView *tableExample = [[ExampleView alloc] initWithFrame:b];
tuiTableViewContainer.rootView = tableExample;

The ExampleView's nsView property is set in the last statement when TUINSView's setRootView method is called. So adding a NSView to TUIView in the initWithFrame: method before it won't work.

The ExampleProject works because text fields are added to the table cells, which are initialized after TUIViewNSViewContainer's nsView is set.

@jspahrsummers
Copy link

Fixed by #70. Thanks for reporting this!

@jspahrsummers jspahrsummers removed their assignment May 22, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants