FROM : Koen van der Drift
DATE : Sat Jan 25 17:24:27 2003
Hi,
I am struggling to get an NSTextView into a custom view, and would
appreciate any help. Basically what I want is a view which has two
textviews, each with their own text container and layoutmanager, but which
share the textstorage.
So, based on chapter 12 in Hillegass' book, I created a customview. If I
use his code in drawRect, it just works fine, so I assume the view is set
up correctly.
Now I would like to add an NSTextView to it, and I am following the Cocoa
docs from Apple, 'Creating an NSTextView programmatically'. In the custom
view's initWithFrame, I do the following:
- (id)initWithFrame:(NSRect)frameRect
{
if ( [super initWithFrame:frameRect] )
{
NSWindow *aWindow = [self window];
NSRect cFrame = [[aWindow contentView] frame];
NSTextView *textView = [[NSTextView alloc] initWithFrame:cFrame];
[aWindow setContentView:textView];
[aWindow makeKeyAndOrderFront:nil];
[aWindow makeFirstResponder:textView];
[textView setString:@"test"];
[textView release];
}
return self;
}
However, the view is empty, with the striped background. If I step through
the code, I noticed that [self window] at this point returns nil, so that
might be a problem.
Any suggestions how to make this work?
thanks,
- Koen.
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
DATE : Sat Jan 25 17:24:27 2003
Hi,
I am struggling to get an NSTextView into a custom view, and would
appreciate any help. Basically what I want is a view which has two
textviews, each with their own text container and layoutmanager, but which
share the textstorage.
So, based on chapter 12 in Hillegass' book, I created a customview. If I
use his code in drawRect, it just works fine, so I assume the view is set
up correctly.
Now I would like to add an NSTextView to it, and I am following the Cocoa
docs from Apple, 'Creating an NSTextView programmatically'. In the custom
view's initWithFrame, I do the following:
- (id)initWithFrame:(NSRect)frameRect
{
if ( [super initWithFrame:frameRect] )
{
NSWindow *aWindow = [self window];
NSRect cFrame = [[aWindow contentView] frame];
NSTextView *textView = [[NSTextView alloc] initWithFrame:cFrame];
[aWindow setContentView:textView];
[aWindow makeKeyAndOrderFront:nil];
[aWindow makeFirstResponder:textView];
[textView setString:@"test"];
[textView release];
}
return self;
}
However, the view is empty, with the striped background. If I step through
the code, I noticed that [self window] at this point returns nil, so that
might be a problem.
Any suggestions how to make this work?
thanks,
- Koen.
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
| Related mails | Author | Date |
|---|---|---|
| Koen van der Drift | Jan 25, 17:24 | |
| Koen van der Drift | Jan 25, 22:43 | |
| Koen van der Drift | Jan 26, 21:37 |






Cocoa mail archive

