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: NSTableView text editing notifications/delegation vs. attributed string cells?




On Feb 28, 2006, at 9:25 AM, Jim Correia wrote:

The notifications/delegate methods for control text editing look like this:

@interface NSObject(NSTextDelegate)
- (BOOL)textShouldBeginEditing:(NSText *)textObject; /* YES means do it */
- (BOOL)textShouldEndEditing:(NSText *)textObject; /* YES means do it */
- (void)textDidBeginEditing:(NSNotification *)notification;
- (void)textDidEndEditing:(NSNotification *)notification;
- (void)textDidChange:(NSNotification *)notification; /* Any keyDown or paste which changes the contents causes this */
@end


Suppose I have a cell for which -allowsEditingTextAttributes is true. What is the preferred way to get back the attributedString in textShouldEndEditing?

NSText doesn't appear to have attributed string accessor methods. I could certainly do the if ([textObject respondsToSelect:...]) dance here, but I'm wondering if I might have missed something obvious?


These probably aren't the methods you're looking for. The best thing is to act as the table view's delegate, and implement the methods defined in NSControl.h starting with control:textShouldBeginEditing:. The methods you list above are those that the controls themselves (such as NSTableView) implement to receive delegate messages from the field editor; in these methods they then call out to their own delegates using methods like control:textShouldBeginEditing:. If you were implementing a table view subclass, you could override the NSText delegate methods, but that would have to be done with great care.


The other thing is that in the AppKit as it stands, NSText is an abstract class; the concrete subclass used is NSTextView. The distinction between NSText and NSTextView is a historical artifact, and you may assume that field editors will be NSTextViews.

Douglas Davidson

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >NSTableView text editing notifications/delegation vs. attributed string cells? (From: Jim Correia <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.