I have a custom view on which I place multiple NSTextViews, but when printed 
only the *content* last NSTextView placed actually shows up. That is, to make 
sure I am placing view appropriately my NSTextView subclass draws a box around 
its bounds. The box shows up, but no text inside even though I can verify that 
the text storage has content.

I have to construct everything manually since I may need multiple NSTextViews 
for a single NSTextStorage:

- (void)addLetter:(NSTextStorage *)letter mergeData:(NSDictionary *)data
{
  // copy letter & merge
  [textStorage release];
  textStorage = [[NSTextStorage alloc] initWithAttributedString:letter];
  [textStorage processMergeCodesWithValues:data];
  
  // use our own layout manager
  NSLayoutManager *manager = [[NSLayoutManager alloc] init];
  manager.delegate = self;
  [textStorage addLayoutManager:manager];
  [manager release];  // textStorage will own
  
  // add a page
  [self addPage];
}

- (void)addPage
{
  NSRect frame = self.frame;
  frame.size.height += pageSize.height;
  self.frame = frame;
  
  NSTextContainer *container = [[NSTextContainer alloc] 
initWithContainerSize:pageSize];
  NSLayoutManager *layoutManager = [[textStorage layoutManagers] 
objectAtIndex:0];
  [layoutManager addTextContainer:container];
  [container release];
  
  AIRTextView *textView = [[AIRTextView alloc] 
initWithFrame:NSMakeRect(pageOrigin.x, pageOrigin.y, pageSize.width, 
pageSize.height) textContainer:container];
  [textView setMinSize:NSMakeSize(pageSize.width, 0.5)];
  [textView setMaxSize:NSMakeSize(pageSize.width, pageSize.height)];
  [textView setVerticallyResizable:NO];
  [textView setHorizontallyResizable:NO];
  [textView setAutoresizingMask:NSViewNotSizable];
  [self addSubview:textView];
  [textView release];
  
  // this should cause layout
  [layoutManager glyphRangeForTextContainer:container];
  
  // update origin for next page
  pageOrigin.y += pageSize.height;
}

The -addLetter:mergeData: is called once per page as in my test case the 
"letter" will fully render in a single page. If I only call it once, the page 
shows. If I call it any more than once only the last NSTextView will show its 
text content in the last NSTextView placed.

TIA,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to