On Thu, Jul 31, 2008 at 4:04 PM, I. Savant <[EMAIL PROTECTED]> wrote:
> On Thu, Jul 31, 2008 at 2:26 AM, Negm-Awad Amin <[EMAIL PROTECTED]> 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 protected])

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 [EMAIL PROTECTED]

Reply via email to