Restrict NSTextField to only allow numbers

Try to make your own NSNumberFormatter subclass and check the input value in -isPartialStringValid:newEditingString:errorDescription: method. @interface OnlyIntegerValueFormatter : NSNumberFormatter @end @implementation OnlyIntegerValueFormatter – (BOOL)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error { if([partialString length] == 0) { return YES; } NSScanner* scanner = [NSScanner scannerWithString:partialString]; if(!([scanner scanInt:0] && [scanner isAtEnd])) { NSBeep(); return NO; } return YES; } @end And … Read more

NSTextField – White text on black background, but black cursor

Since in practice the NSText* returned by -currentEditor for an NSTextField is always an NSTextView*, I added the following code to my custom NSTextField subclass: -(BOOL) becomeFirstResponder { BOOL success = [super becomeFirstResponder]; if( success ) { // Strictly spoken, NSText (which currentEditor returns) doesn’t // implement setInsertionPointColor:, but it’s an NSTextView in practice. // … Read more

NSTextField or NSTextView?

Could someone explain to me what are the main differences between NSTextField and NSTextView? I know that NSTextView has more features and is usually used for longer texts, and NSTextField is usually used for one-line plain text fields, but if I understand correctly, NSTextField can be also used with attributed strings and with multiple lines… … Read more

NSViewController User Interface State Restoration

To achieve aforementioned effect let’s create NSSearchField and a custom class named RestoredWindow containing just one property: import Cocoa class RestoredWindow: NSWindow { override class var restorableStateKeyPaths: [String] { return [“self.contentViewController.searchField.stringValue”] } } Assign this custom class to Window Controller in Identity Inspector. Next, let’s bind searchField.stringValue property to ViewController in Value section of Bindings … Read more

How to let NSTextField grow with the text in auto layout?

The method intrinsicContentSize in NSView returns what the view itself thinks of as its intrinsic content size. NSTextField calculates this without considering the wraps property of its cell, so it will report the dimensions of the text if laid out in on a single line. Hence, a custom subclass of NSTextField can override this method … Read more

Text change notification for an NSTextField

If you just want to detect when the value of a text field has changed, you can use the controlTextDidChange: delegate method that NSTextField inherits from NSControl. Just connect the delegate outlet of the NSTextField in the nib file to your controller class, and implement something like this: – (void)controlTextDidChange:(NSNotification *)notification { NSTextField *textField = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)