Note that there are some explanatory texts on larger screens.

plurals
  1. POGet string from NSTextView then return cursor to beginning
    primarykey
    data
    text
    <p>I would like to enter text in a <code>NSTextView</code> so that when I hit return the <code>NSTextView</code> clears with the cursor going back to the original position. Then the entered text displays on the screen using the <code>drawRect</code> of an <code>NSView</code>.</p> <p>This what I have currently which doesn't work. Basically <code>self.outputString</code> is always the current value of <code>[textview string]</code> even though I draw and then clear. The current code below doesn't draw any string to the screen. If I remove <code>[textview setString:@""]</code> then the current text always shows what I'm writing. </p> <pre><code>- (void)drawRect:(NSRect)dirtyRect { [[NSColor whiteColor] setFill]; NSRectFill(dirtyRect); // Drawing code here. NSPoint point = NSMakePoint(50.0f, 700.0f); NSMutableDictionary *font_attributes = [[NSMutableDictionary alloc] init]; NSFont *font = [NSFont fontWithName:@"Futura-MediumItalic" size:35.0f]; [font_attributes setObject:font forKey:NSFontAttributeName]; [self.outputString drawAtPoint:point withAttributes:font_attributes]; [font_attributes release]; } - (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector { [self enterPressed:[textView string]]; [textView setString:@""]; NSRange range = { 0, 0 }; [self.textView setSelectedRange: range]; return YES; } - (void) enterPressed:(NSString*)stringEntered { NSLog(@"enter pressed with string: %@", stringEntered); self.outputString = stringEntered; [self setNeedsDisplay:YES]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload