Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem binding NSTextView's attributedString



On Thu, Jul 31, 2008 at 4:04 PM, I. Savant <email@hidden> wrote:
> On Thu, Jul 31, 2008 at 2:26 AM, Negm-Awad Amin <email@hidden> wrote:
>
>>> I've checked changes to selectedPage can be observed OK so I'm not
>>> sure what I'm missing from the equation. Any tips?
>>
>> I think, that your solution should work. I do not know, why it doesn't.
>
>  This is because Pete hasn't posted any code. It doesn't make much
> sense on the surface of things that your selectedPage property is
> "observed OK" but the mechanism isn't working. This leads me to
> believe your "working" assumption may be incorrect. Post your
> "selectedPage" related code for review.

Right-o, here goes.

I have the property defined in the document.h file as

@interface TheDocument : NSDocument {
	PageEntity *_selectedPage;
}

@property(assign) PageEntity *selectedPage;

@end

---------------------

The implementation in document.m is either

@implementation TheDocument

@synthesize selectedPage=_selectedPage;

@end

------- or -------

@implementation TheDocument

- (void)setSelectedPage:(PageEntity*)newPage
{
	if (newPage == _selectedPage)
		return;
		
	[self willChangeValueForKey:@"selectedPage"];
	_selectedPage = newPage;
	[self didChangeValueForKey:@"selectedPage"];
}

- (PageEntity*)selectedPage
{
	// Probably OTT
	[self willAccessValueForKey:@"selectedPage"];
	PageEntity *page = _selectedPage;
	[self didAccessValueForKey:@"selectedPage"];

	return page	
}

@end

---------

In my view controller, I can observe the property using the following
code (where self.document is a property of the view controller
subclass):

[self.document addObserver:self forKeyPath:@"selectedPage"
options:NSKeyValueObservingOptionNew context:MyObserverContext];

I receive change notifications correctly in
observeValueForKeyPath:ofObject:change:context: but if I bind an
NSTextView's attributedString object to
document.selectedPage.textContent, the content of the view doesn't
change when selectedPage changes.

I hope that shows what I'm trying to do more clearly.

Cheers,
Pete
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >Problem binding NSTextView's attributedString (From: "Pete Callaway" <email@hidden>)
 >Re: Problem binding NSTextView's attributedString (From: Negm-Awad Amin <email@hidden>)
 >Re: Problem binding NSTextView's attributedString (From: "I. Savant" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.