Delegate for multiple NSTextViews
Delegate for multiple NSTextViews
- Subject: Delegate for multiple NSTextViews
- From: Rob Minerick <email@hidden>
- Date: Wed, 14 Apr 2004 16:01:12 -0500
Hi everyone,
What I have is multiple views of a single NSTextStorage and each view
has a delegate. The problem I'm having is that only the first text view
I create actually calls the delegate when I make a change in the view.
The other views never call their delegate. To illustrate the problem,
I've taken the simple TextViewConfig example from Apple
(
http://developer.apple.com/samplecode/TextViewConfig/
TextViewConfig.html) and modified it accordingly:
@implementation Controller
#define SLIDE_WIDTH 256.0
#define SLIDE_HEIGHT 192.0
#define SLIDE_BORDER 8.0
#define NUM_SLIDES 20
- (void)awakeFromNib {
NSTextStorage *textStorage = [singleTextView textStorage];
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
unsigned i;
[singleTextView setDelegate:self];
[customView setFrame:NSMakeRect(0, 0, 2 * (SLIDE_WIDTH + 2 *
SLIDE_BORDER),
2 * (SLIDE_BORDER + NUM_SLIDES * (SLIDE_HEIGHT + SLIDE_BORDER)))];
[customView setBounds:NSMakeRect(0, 0, SLIDE_WIDTH + 2 *
SLIDE_BORDER, SLIDE_BORDER + NUM_SLIDES * (SLIDE_HEIGHT +
SLIDE_BORDER))];
[textStorage addLayoutManager:layoutManager];
for (i = 1; i <= NUM_SLIDES; i++) {
NSTextContainer *textContainer = [[NSTextContainer alloc]
initWithContainerSize:NSMakeSize(SLIDE_WIDTH, SLIDE_HEIGHT)];
NSTextView *textView = [[NSTextView alloc]
initWithFrame:NSMakeRect(SLIDE_BORDER,
SLIDE_BORDER + (NUM_SLIDES - i) * (SLIDE_HEIGHT +
SLIDE_BORDER),
SLIDE_WIDTH, SLIDE_HEIGHT) textContainer:textContainer];
[textView setDelegate:self];
[layoutManager addTextContainer:textContainer];
[textContainer release];
[customView addSubview:textView];
[textView release];
}
}
- (void)textDidBeginEditing:(NSNotification *)aNotification
{
NSLog(@"textDidBeginEditing");
}
@end
Does anyone have an explanation as to why the delegate is called when
singleTextView is edited, but not for textView? Any ideas would be
good, I'm at my wits end with this one.
--
Rob
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.