Re: Problem binding NSTextView's attributedString
Re: Problem binding NSTextView's attributedString
- Subject: Re: Problem binding NSTextView's attributedString
- From: "Pete Callaway" <email@hidden>
- Date: Thu, 31 Jul 2008 21:02:04 +0100
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:
This email sent to email@hidden