• 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: Newbie question: NSDocument and standard file formats
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question: NSDocument and standard file formats


  • Subject: Re: Newbie question: NSDocument and standard file formats
  • From: Heinrich Giesen <email@hidden>
  • Date: Mon, 26 Nov 2007 10:44:10 +0100


On 25.11.2007, at 18:42, Andrew Ebling wrote:

  What I want to do is read an existing file format:

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:
(NSError **)outError
{
	NSImage *img = [[NSImage alloc] initWithData:data];
	[imageView setImage:img];
	[img release];

     	return YES;
}

However, that naive code does not work, because the data contained in
the NSData does not appear to be in a format that NSImage understands.


As jerry already wrote:
But the Cocoa Document Architecture does not do stuff with the data in
the file.


It doesn' work because you send the 'img' too early to the 'imageView'. The new
document is still in the loading phase and therefore 'imageView' is empty.
Insert NSLog( @"imageView is %p", imageView ); and you get ' .... 0x0'. In this
method -readFromData:ofType:error: you may check the data for correctness and
(if valid) assign the data to an instance variable: imgData = [data retain];
(do not forget to release imgData in -dealloc:)


In the NSDocument method -windowControllerDidLoadNib: you can use imgData, create
an NSImage and send it to the imageView, because it is now loaded, as the method says.


	Heinrich

--
Heinrich Giesen
email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Prev by Date: Re: Multiple applications, one NSUserDefaults object?
  • Next by Date: UTI's and document packages
  • Previous by thread: Re: Newbie question: NSDocument and standard file formats
  • Next by thread: Re: Newbie question: NSDocument and standard file formats
  • Index(es):
    • Date
    • Thread