cocoa

Restrict NSTextField to only allow numbers

狂风中的少年 提交于 2020-03-12 07:31:10
问题 How do I restrict a NSTextfield to allow only numbers/integers? I've found questions like this one, but they didn't help! 回答1: 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**

How do I paint/draw/render a dot or color a pixel on the canvas of my window with only a few lines in Obj-C on Mac OS X using Xcode?

假如想象 提交于 2020-03-05 00:25:26
问题 [Edit:] Moving forward from phase 1 of my project here: How do I re-define size/origin of app window in code, overriding nib/xib file parameters, with Obj-C, Xcode 11.3.1 on Mac OS X 10.15.2 (Catalina)? My current objective is pretty simple (at least in the abstract): I want to (re-)color a pixel in my blank Mac OS X application window. I want to do this economically, with as few lines of code as humanly possible, because looking at large chunks of code is a real eyesore. I really did not

NSCell with divisions

回眸只為那壹抹淺笑 提交于 2020-03-03 12:49:24
问题 I want to know if there is a way of drawing an NSCell like the following sample. The idea is to fit in the same column, 3 rows, the first one with enough space for a Title, and the rest with 2 columns. TITLE_ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ ____ DATA_TITLE_1: DATA_VALUE_1 _ _ _ DATA_TITLE_2: DATA_VALUE_2 DATA_TITLE_3: DATA_VALUE_1 _ _ _ DATA_TITLE_4: DATA_VALUE_2 Notes: The "_ _ _" were suposed to be three spaces (I don't know how to represent

NSCell with divisions

杀马特。学长 韩版系。学妹 提交于 2020-03-03 12:49:06
问题 I want to know if there is a way of drawing an NSCell like the following sample. The idea is to fit in the same column, 3 rows, the first one with enough space for a Title, and the rest with 2 columns. TITLE_ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ ____ DATA_TITLE_1: DATA_VALUE_1 _ _ _ DATA_TITLE_2: DATA_VALUE_2 DATA_TITLE_3: DATA_VALUE_1 _ _ _ DATA_TITLE_4: DATA_VALUE_2 Notes: The "_ _ _" were suposed to be three spaces (I don't know how to represent

NSFilePresenter methods never get called

与世无争的帅哥 提交于 2020-02-28 04:58:47
问题 I'm trying to write a simple (toy) program that uses the NSFilePresenter and NSFileCoordinator methods to watch a file for changes. The program consists of a text view that loads a (hardcoded) text file and a button that will save the file with any changes. The idea is that I have two instances running and saving in one instance will cause the other instance to reload the changed file. Loading and saving the file works fine but the NSFilePresenter methods are never called. It is all based

Cocoa nsview change cursor

妖精的绣舞 提交于 2020-02-27 23:09:27
问题 I tried to change the default cursor in my cocoa application. I read about this but the standard approach isn't working for me. I try to add to my OpenGLView subclass this method: - (void) resetCursorRects { [super resetCursorRects]; NSCursor * myCur = [[NSCursor alloc] initWithImage:[NSImage imageNamed:@"1.png"] hotSpot:NSMakePoint(8,0)]; [self addCursorRect: [self bounds] cursor: myCur]; NSLog(@"Reset cursor rect!"); } It`s not working. Why? 回答1: There're two ways you can do it. First - the

Binding search field and table view in cocoa

穿精又带淫゛_ 提交于 2020-02-27 22:57:46
问题 I have a nstableview. I would like to filter the results based on the characters entered in a search bar in OSX. So how do i bind the table view and the search field in OSX not in IOS? :) Thanks. 回答1: I have a project that you can download and look how it works. The steps are as : Drag NSArrayController, set all bindings with this. Create NSSearchField. In binding inspector, Search "Bind to ArrayController". Set Controller Key to "filterPredicate". Set Predicate Format to "property1 contains

如何以编程方式在iPhone上发送短信?

≯℡__Kan透↙ 提交于 2020-02-26 15:56:24
是否有人知道有可能以及如何通过官方的SDK / Cocoa Touch通过 iPhone 以编程方式发送 SMS ? #1楼 用这个: - (void)showSMSPicker { Class messageClass = (NSClassFromString(@"MFMessageComposeViewController")); if (messageClass != nil) { // Check whether the current device is configured for sending SMS messages if ([messageClass canSendText]) { [self displaySMSComposerSheet]; } } } - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { //feedbackMsg.hidden = NO; // Notifies users about errors associated with the interface switch (result) { case

Can't get NSTableView to display any text whatsoever

限于喜欢 提交于 2020-02-25 09:23:07
问题 I've been developing on iOS for some time, but am very new to Cocoa development, and something seemingly very simple is stumping me. I have an NSTableView, hooked up to a subclass of NSWindowController as both datasource and delegate. I have an array of "File" objects (my model class) and want to populate one column of my tableview with file types, and another with timestamps. The dataSource methods are definitely being called, as verified by setting breakpoints. In fact, I end up with an

How to control the scientifc style of NSNumberFormatter?

别等时光非礼了梦想. 提交于 2020-02-24 18:00:48
问题 I'm converting a long string representing a very big or small number to a string in scientific notation. E.g. 9999999999999999999999999 to 9.999999999999999E24. I use NSNumberFormatter. NSNumberFormatter *ns = [[NSNumberFormatter alloc] init]; [ns setNumberStyle: NSNumberFormatterScientificStyle]; NSString *result = [ns stringFromNumber: [ns numberFromString: aBigOrSmallString]]; [ns release]; But how can I control the precision part? For example, from 912345678 to 9.12E8 or 9.1234E8. 回答1: