RE: Using NSCell in a custom view?
RE: Using NSCell in a custom view?
- Subject: RE: Using NSCell in a custom view?
- From: Keith Blount <email@hidden>
- Date: Wed, 20 Apr 2005 02:56:43 -0700 (PDT)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Sorry to reply to my own post, but this is driving me
crazy as it seems it should be really simple, but the
only examples I can find anywhere are all for
NSMatrix, whereas all I want to do is create and draw
a text cell in an arbitrary position in a custom
NSView, which can be edited on mouse down...
Does anybody know of any examples/tutorials out there,
or can anyone give me a simple example/pointer, on how
to draw an NSCell in a view in such a way that the
NSCell can be edited and the field editor is removed
upon editing ending? I think it is this last part
where I am going wrong. Here is what I have so far
which draws strangely after an edit (ie doesn't work
properly):
- (void)mouseDown:(NSEvent *)theEvent
{
[cell setStringValue:string];
[cell editWithFrame:cellRect
inView:self
editor:[[self window] fieldEditor:YES
forObject:self]
delegate:self
event:theEvent];
}
- (void)setString:(NSString *)str
{
[str retain];
[string release];
string = str;
}
- (BOOL)textShouldEndEditing:(NSText *)textObject
{
[self setString:[textObject string]];
return YES;
}
- (void)textDidEndEditing:(NSNotification
*)notification
{
//[cell endEditing:[notification object]];
[self setNeedsDisplay:YES];
}
- (void)drawRect:(NSRect)aRect
{
[[NSColor yellowColor] set];
[NSBezierPath fillRect:aRect];
[cell setStringValue:string];
// I have cut the cellRect calculation here to save
space
[cell drawWithFrame:cellRect inView:self];
}
If anyone can tell me where I am going wrong, or point
me in the direction of information on how I can create
a custom view that uses text cells, I would be very
grateful.
Many thanks in advance,
Keith
---Original message---
Hello,
I know this is the sort of question that gets asked
often, and yet I have searched the Cocoabuilder
archives, cocoadev, read the NSCell articles on
stepwise, the docs on NSCell and NSControl (class
descriptions and "Controls and Cells") and can still
not find what I am looking for.
I have a custom view in which I want to click to
create text which can be placed arbitrarily. (This is
actually a margin next to a text view which stores any
number of notes that are aligned with the text.)
Having tried various approaches, I am now trying to
implement this using NSCells.
The problem is, I can find nothing that gives a really
good overview of how to create a custom view that
allows the user to create and edit cells. As a test, I
have tried creating an NSView subclass that draws a
single text cell using drawWithFrame:inView: and
monitors mouseDown:, calling editWithFrame: when there
is a mouseDown event. I can edit text, but I get a
number of drawing issues (if I select text and hit
enter, I just get a blank square).
Are there any good tutorials out there or does anybody
have any experience of doing this that they would be
willing to share? Essentially all I need to know is
how to create, monitor, move and edit a text cell
within a custom view. I know this should be really
simple, but I have found the docs really vague on this
issue.
Many thanks in advance for any help,
Keith
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden