cocoa

How to make NSTextView balance delimiters with a double-click?

≯℡__Kan透↙ 提交于 2020-01-17 12:38:51
问题 It's common to have a text editor for code or other structured content that balances delimiters of some sort; when you double click on a { it selects to the matching }, or similarly for ( ) pairs, [ ] pairs, etc. How can I implement this behavior in NSTextView in Cocoa/Obj-C? (I will be posting an answer momentarily, since I found nothing on SO about this and spent today implementing a solution. Better answers are welcome.) ADDENDUM: This is not the same as this question, which is about

Custom object on NSPasteboard

假装没事ソ 提交于 2020-01-17 10:23:38
问题 I am using NSPasteboardWriting protocol for writing custom object on NSPasteboard. How to create UTI for custom object? - (NSArray *)writableTypesForPasteboard:(NSPasteboard *)pasteboard { static NSArray *writableTypes = nil; if (!writableTypes) { writableTypes = [[NSArray alloc] initWithObjects:[FileSystemItem class], nil]; } NSLog(@"writable%@", writableTypes); return writableTypes; } - (id)pasteboardPropertyListForType:(NSString *)type { NSLog(@"type = %@", type); return type; }

Setting the background of a custom view with an image results in a black background

白昼怎懂夜的黑 提交于 2020-01-17 08:55:20
问题 I have a problem setting the background of my subclassed NSView called TitlebarView . I want to use an image as a background via colorWithPattternImage , but the result is a black background not the image i gave the method as a parameter. Here's my code of TitlebarView : - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { NSString* pathToTitlebarBGImage = [[NSBundle mainBundle] pathForResource:@"titlebar_bg" ofType:@"png" inDirectory:@"Resources/gui_images"];

How to handle freezing programm at loading xml from bad url?

☆樱花仙子☆ 提交于 2020-01-17 07:55:28
问题 I want to handle freezing my program, when it load an xml from bad address. I tryed it with using @try and @catch, but it doesn't work. Can I use some alternative handling? @try{ NSString *test=[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%@",addressLabel.text,portLabel.text]] encoding:NSUTF8StringEncoding error: nil]; } @catch (NSException *ex) { NSLog(@"Bad IP address"); return; } 回答1: Run your XML Parser in NSThread and use

Xcode - one nib, two classes - outlets in second class not connecting?

蓝咒 提交于 2020-01-17 06:32:16
问题 I've got a single nib file and want to connect some elements to methods in one class (which is the AppDelegate) and some to another class (which is just an NSObject). So the schema looks like this buttonOne -> [mainClass set] buttonTwo -> [auxCalss set] textFieldOne -> mainClass.field textFieldTwo -> auxClass.field The two [set] actions are connected to the two classes and work fine, but only textField one is connected to mainclass, which is also the AppDelegate. TextFieldTwo doesn't work

Xcode - one nib, two classes - outlets in second class not connecting?

ε祈祈猫儿з 提交于 2020-01-17 06:32:00
问题 I've got a single nib file and want to connect some elements to methods in one class (which is the AppDelegate) and some to another class (which is just an NSObject). So the schema looks like this buttonOne -> [mainClass set] buttonTwo -> [auxCalss set] textFieldOne -> mainClass.field textFieldTwo -> auxClass.field The two [set] actions are connected to the two classes and work fine, but only textField one is connected to mainclass, which is also the AppDelegate. TextFieldTwo doesn't work

Swift ViewController does not respond to -getFile, Could not connect action, target class

只愿长相守 提交于 2020-01-17 06:06:28
问题 My code works all fine but there is always two console message every time I run it. app works fine but the messages just bugs me so much. Could anyone tell me what is wrong with my code and what does these console message means,thanks 2016-06-13 14:31:15.014 LazyHackintoshGenerator[1625:37250] Could not connect action, target class LazyHackintoshGenerator.ViewController does not respond to -getFile: 回答1: Likely a control's action in your storyboard is linked to a method getfile that no longer

Window is not releasing when switching to another window

二次信任 提交于 2020-01-17 04:45:13
问题 I am creating a Mac application in which I have mainwindow with some buttons. When I click button it will open a DetailWindow with NSTableview. Every buttonclickevent change the data in NSTableView. Here is my code: In my mainWindow.m FIle - (IBAction)btn1Event:(id)sender { if (!detailwindow) { detailwindow = [[DetailWindow alloc] initWithWindowNibName:@"DetailWindow"]; detailwindow.mainwindow = self; } detailwindow.title = @"First"; [detailwindow showWindow:self]; } - (IBAction)btn2Event:(id

Encoding problem in sqlite and objective-c

亡梦爱人 提交于 2020-01-17 04:34:06
问题 I have a file with contents something like this: INSERT INTO table VALUES (NULL,'° F','Degrees Fahrenheit'); INSERT INTO table VALUES (NULL,'° C','Degrees Celsius'); Now, to parse this, I have something like this: NSString *sql = [NSString stringWithContentsOfFile:filename]; Printing this string to the console looks correct. Then, I want to make an actual insert statement out of it: const char *sqlString = [query UTF8String]; const char *endOfString; if (sqlite3_prepare_v2(db, sqlString +

How to access items in the main nib from a document nib?

允我心安 提交于 2020-01-17 03:46:10
问题 I'm making an NSDocument-based application in which I have an inspector window. This inspector window is part of Pwnshop.nib which is my main nib. I have another nib called 'Document.nib,' which is the document window. I want to be able to change the inspector based on which document window is the active one, sorta like Interface Builder's inspector. The problem is that I want to access an object in another nib . Note that there are multiple document windows, but only one inspector window.