On 21 Jun 2010, at 21:35, Michael Babin wrote:

> On Jun 20, 2010, at 8:11 AM, Bernard Knaepen wrote:
> 
>> The trouble I have is to access the attributed string within my code to 
>> later draw in a custom view. I am trying something like this:
>> 
>> NSManagedObjectContext *context  = [self managedObjectContext];
>> NSManagedObjectModel   *model    = [self managedObjectModel];
>> NSDictionary           *entities = [model entitiesByName];
>> NSEntityDescription    *entity   = [entities valueForKey:@"signatures"];
>> 
>> NSFetchRequest * fetch = [[NSFetchRequest alloc] init];
>> [fetch setEntity: entity];
>> 
>> NSArray *results = [context executeFetchRequest:fetch error:nil];
>>      
>> myData = [[results objectAtIndex:0] valueForKey:@"sigText"];
>> 
>> NSAttributedString *signatureView = (NSAttributedString *)[NSUnarchiver 
>> unarchiveObjectWithData:myData];
>> 
>> [mypreview lockFocus];
>> [signatureView drawAtPoint:myPoint];
>> [mypreview unlockFocus];
>> 
>> 
>> Obviously something is wrong since the text is not drawn and the console 
>> outputs:
>> 
>> -[NSConcreteMutableData drawAtPoint:]: unrecognized selector sent to 
>> instance 0x114a3afb0
> 
> From the error message, it would appear signatureView is not an 
> NSAttributedString (NSMutableData, instead). So work backwards. You're making 
> assumptions in your code: valueForKey:@"sigText" returns an NSData object, 
> using NSUnarchiver on it yields an NSAttributedString. Test them (step 
> through in debugger, NSLog(), etc) and see if your assumptions are valid. If 
> they aren't valid, then move back up the chain to where the value is stored 
> and see if you're storing the correct data. If your assumptions are valid, 
> then I would suspect there might be some intervening code and you may be 
> running into object ownership issues (retain/release, zombies).
> 
> 

Problem solved. In the .xib file, I had binded the NSTextView 'Data' to 
sigText. I now use the 'attributed string' value for the binding and everything 
is fine (shame on me for not having seen this option before).

Mike, thanks your tip ;-)


Bernard.

 

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to