nstextfield

NSTextfield + NSMenu and first responder

做~自己de王妃 提交于 2019-12-05 11:00:24
I'm trying to implement my own autocomplemention system (result is pull from an sqlite database) I've set up a NSTextField and the appropriate delegate. Each time the text in the NSTextField change, it call - (void)controlTextDidChange:(NSNotification *)aNotification method It work fine, in this method I build a menu programtically and finally I call/show it with that code: NSRect frame = [address frame]; NSPoint menuOrigin = [[address superview] convertPoint:NSMakePoint(frame.origin.x, frame.origin.y+frame.size.height-25) toView:nil]; NSEvent *event = [NSEvent mouseEventWithType

NSTextField's attributed string is delayed in rendering

怎甘沉沦 提交于 2019-12-05 06:19:36
I've got an Label (NSTextField) in IB that's bound to a controller. The controller, on awakeFromNIB, sets the attributedStringValue of the label to contain some coloured text and a link or two. When you see the label it contains the correct string value, but some of the formatting is lost - until you click on the label, and it updates to contain the correct formatting. I'm using this code to set the value: [self.testTextField setAllowsEditingTextAttributes:YES]; [self.testTextField setSelectable:YES]; NSMutableAttributedString *linkString = [[NSMutableAttributedString alloc] initWithString:@

How to make NSTextField use custom subclass of NSTextFieldCell?

痴心易碎 提交于 2019-12-05 05:13:49
I've been looking for a solution to make my NSTextField bottom-aligned and I've found this and adjusted it for my needs. So now I have this custom NSTextFieldCell but how do I tell my NSTextFields to use this class (programmatically)? Have you tried setCell: method of the NSControl class? - (void)setCell:(NSCell *)aCell Since you ask how to do it programmatically, you can also use the setCellClass: method on your NSTextField subclass. Call it in the load or initialize class methods: +(void)load { [self setCellClass:[MyTextFieldCell class]]; } It will not have any bearing on your text fields

NSTextField autocompletion delegate method not called

老子叫甜甜 提交于 2019-12-05 03:50:40
I implemented the following delegate method for NSTextField to add autocompletion support: - (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index The issue is that this method never gets called. I can verify that the delegate of the NSTextField is set properly because the other delegate methods function as they should. You'll need to get complete: called on the text field's field editor at some point. That's what triggers the completions menu, but it doesn't get called

Problems setting FirstResponder in Cocoa Mac OSX

一世执手 提交于 2019-12-05 01:43:08
问题 Im working on a tiny app just to learn cocoa, and Im having a hard time with setting FirstResponder to some NSTextFields. When the view opens, I want the first NSTextField, clientNumber, to be selected, so I trigger [clientNumber becomeFirstResponder] at the end of my loadView method, but it does not select the text field. But when I click the button that fires the (IBAction)addToArray method, it selects the right text field. Further do I have another text field, it should contain integers

Vertically Centre Text in NSSecureTextField with subclassing

对着背影说爱祢 提交于 2019-12-05 01:07:54
I'm trying to vertically centre text in my NSTextFields, but one of them is for a password, so it's a NSSecureTextField. I've set it's class to be MDVerticallyCenteredSecureTextFieldCell with the following implementation: - (NSRect)adjustedFrameToVerticallyCenterText:(NSRect)frame { // super would normally draw text at the top of the cell NSInteger offset = floor((NSHeight(frame) - ([[self font] ascender] - [[self font] descender])) / 2); return NSInsetRect(frame, 0.0, offset+10); } - (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)editor delegate:(id)delegate

make nstextfield single line

早过忘川 提交于 2019-12-04 22:59:53
how to make NSTextField really single line? I created a text field programmatically. when the return key is pressed, all text is selected. but I can still paste multiple lines of text. And when I press Arrow-right or Arrow down, it scroll to the next line. There aren't these issues if I use IB and set the "use single line mode", but I couldn't find the right method to set it programmatically. Peter Hosey Have you tried telling the field's cell to set whether it uses single-line mode ? [myTextField.cell setUsesSingleLineMode:YES]; This works for me when programmatically creating controls:

how to detect double Click in NSTextField

佐手、 提交于 2019-12-04 17:38:26
I have a custom NSTextField and I'd like to detect double clicks by the user in the text field. My goal: I want to be able to double click on a parenthesis in an expression, such as "(2+2) = 4" and have it select everything inside the matching parentheses. Thought I could do this with... - (void)textView:(NSTextView *)textView doubleClickedOnCell:(id <NSTextAttachmentCell>)cell inRect:(NSRect)cellFrame atIndex:(NSUInteger)charIndex; but it never gets called in my custom NSTextField. Then I thought I could override -mouseDown, but that isn't getting called either. I'm stumped. Any suggestions

NSStatusItem with NSPopover and NSTextField

亡梦爱人 提交于 2019-12-04 15:24:42
I have a NSStatusItem that displays a NSPopover which contains a NSTextField but the text field isn't editable although it has been so be so in Xcode. Now this is a known bug and there is apparently a solution someone posted here . I really need to work around this bug. I'll just quote the answer here for convenience: The main problem is the way keyboard events works. Although the NSTextField (and all his superviews) receives keyboard events, he doesn't make any action. That happens because the view where the popover is atached, is in a window which can't become a key window. You can't access

Simple NSTextList question

流过昼夜 提交于 2019-12-04 14:12:17
问题 I am trying to use NSTextList to display a numeric list in a multi-line NSTextField but it is not working as intended. The sample code used is: - (IBAction)displayResult:(id)sender { NSTextList *list = [[NSTextList alloc] initWithMarkerFormat:self.markerFormat options:1]; // {Decimal} passed as marker format NSMutableParagraphStyle *paragraph = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; [paragraph setTextLists:[NSArray arrayWithObject:list]]; [list release]; NSDictionary