• 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
Re: NSAttributedString and HTML
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSAttributedString and HTML


  • Subject: Re: NSAttributedString and HTML
  • From: Richard Van Deren <email@hidden>
  • Date: Sat, 21 Sep 2002 13:50:54 -0400

I can not see your error, but the code below works for me. When in doubt copy.
You get random objects when your object is not allocated. So that is most likely the problem.

- (void)loadHtmlTextViewData:(NSData *)data
{
NSData *myRichTextData;
NSMutableDictionary *docAttributes;
NSTextStorage *textStorage;
NSMutableAttributedString *resumeAttributedString;
textStorage = [resumeHtmlWindowTextView textStorage];
docAttributes = [[NSMutableDictionary alloc] init];
resumeAttributedString = [[NSMutableAttributedString alloc] init];
[resumeAttributedString initWithHTML:(NSData *)data documentAttributes:(NSDictionary **)docAttributes];
// for rich text save for save as Rich Text, may change to Formatting Objects output type in the future
myRichTextData = [resumeAttributedString RTFFromRange:NSMakeRange(0, [resumeAttributedString length]) documentAttributes:nil];
[self setMyRtfData:myRichTextData];
////////////////////////
[textStorage replaceCharactersInRange:NSMakeRange(0, [[textStorage string] length] )
withAttributedString:(NSAttributedString *)resumeAttributedString];
[resumeHtmlWindowTextView setNeedsDisplay:YES];

[[self window] makeKeyAndOrderFront: self];
[self setMyHtmlData:data];
[thisDocument setMyResumeHtmlData:data];

} // end method

On Saturday, September 21, 2002, at 01:11 AM, Chris Hanson wrote:

There's got to be something I'm just missing here.

I'm trying to create an attributed string with the HTML that I have in another string. I'm doing this from within an NSText delegate method, -[MyDocument textDidChange:]. I'm using Mac OS X 10.2.1 with the latest everything.

Here's my code:

- (NSAttributedString *)attributedStringForHTML:(NSString *)rawString
{
NSData *rawStringData;
NSAttributedString *htmlString;

rawStringData = [rawString dataUsingEncoding:NSUTF8StringEncoding];

htmlString = [[[NSAttributedString alloc] initWithHTML:rawStringData
documentAttributes:NULL] autorelease];

return htmlString;
}

What's strange is that as soon as it hits -[NSAttributedString initWithHTML:documentAttributes:], it throws an exception:

Exception raised during posting of notification. Ignored.
exception: *** +[MyDocument attributedStringWithHTML:documentAttributes:]:
selector not recognized

Of course it's not recognized! I don't want to write my own HTML parser, that's what the AppKit additions to NSAttributedString are for! And how the heck is it getting at MyDocument?

What's odd is that using NSAttributedString like this to work fine for projects like Cocoa Browser. And it certainly doesn't have an implementation of +[MyDocument attributedStringWithHTML:documentAttributes:]. What's going on?

-- Chris

-- Chris Hanson | Email: email@hidden
bDistributed.com, Inc. | Phone: +1-847-372-3955
Making Business Distributed | Fax: +1-847-589-3738
http://bdistributed.com/ | Personal Email: email@hidden
_______________________________________________
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.
_______________________________________________
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.

References: 
 >NSAttributedString and HTML (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: Scaling down an image proportionally
  • Next by Date: Re: NSTextField Focus
  • Previous by thread: Re: NSAttributedString and HTML
  • Next by thread: Re: NSAttributedString and HTML
  • Index(es):
    • Date
    • Thread