• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Delegate for multiple NSTextViews
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Delegate for multiple NSTextViews
      • From: Glenn Andreas <email@hidden>
    • Re: Delegate for multiple NSTextViews
      • From: Douglas Davidson <email@hidden>
  • Prev by Date: Re: Model not paying attention to NSString binding
  • Next by Date: Re: Is there a ruled (row numbered) subclass to NSDocument?
  • Previous by thread: RE: NSString and txt file
  • Next by thread: Re: Delegate for multiple NSTextViews
  • Index(es):
    • Date
    • Thread