cocoa

can't open image with NSOpenPanel

佐手、 提交于 2020-01-14 06:03:42
问题 I use below code for open image with NSOpenPanel but doesn't work //panel=NSOpenPanel NSString *imgg = [NSString stringWithFormat:@"%@",panel.URL]; self.imgUser.image=[NSImage imageNamed:imgg]; 回答1: The problem is that +[NSImage imageNamed:] doesn't load an image by URL. If you read the documentation, it explains what it actually does: it looks for an image stored in the cache under that name, or stored in the app's bundle or AppKit's framework under that filename. There are a large number of

NSTableColumn binding using Collection Operators like @sum

荒凉一梦 提交于 2020-01-14 04:24:10
问题 Mac OS X. CoreData app. NSTableView controlled by NSArrayController bound to managed object context for the Country entity. The Country entity has a 'name' attribute and a to-many relationship, 'branches', to a Branch entity. The Branch entity has a 'sales' attribute (an NSNumber). The NSTableView has two NSTableColumns. The first shows the name of the Country. The second should show the total sales for that Country across all its Branches. The first column's value is bound to the

Move directory to trash

ぐ巨炮叔叔 提交于 2020-01-14 04:21:07
问题 I need to move a directory, including its content, to the trash. I found NSWorkspaceRecycleOperation in the documentation, and wrote this code: NSString *path = [NSString stringWithString:@"/Users/test/Desktop/test"]; NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil]; [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:path destination:@"" files:dirContents tag:nil]; It moves all the content to the trash, but

Move directory to trash

流过昼夜 提交于 2020-01-14 04:20:25
问题 I need to move a directory, including its content, to the trash. I found NSWorkspaceRecycleOperation in the documentation, and wrote this code: NSString *path = [NSString stringWithString:@"/Users/test/Desktop/test"]; NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil]; [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:path destination:@"" files:dirContents tag:nil]; It moves all the content to the trash, but

macOS: Detect all application launches including background apps?

ぐ巨炮叔叔 提交于 2020-01-14 03:56:35
问题 Newbie here. I'm trying to create a small listener for application launches, and I already have this: // almon.m #import <Cocoa/Cocoa.h> #import <stdio.h> #include <signal.h> @interface almon: NSObject {} -(id) init; -(void) launchedApp: (NSNotification*) notification; @end @implementation almon -(id) init { NSNotificationCenter * notify = [[NSWorkspace sharedWorkspace] notificationCenter]; [notify addObserver: self selector: @selector(launchedApp:) name: @

How to delay while retaining a responsive GUI on Cocoa Touch?

荒凉一梦 提交于 2020-01-14 03:09:46
问题 Basically, I have an array of buttons I want to iterate and highlight (among other things) one after another, with a delay in-between. Seems like an easy task, but I can't seem to manage to get it to work cleanly while still being responsive. I started out with this: for MyButton *button in buttons { [button highlight]; [button doStuff]; usleep(800000); // Wait 800 milliseconds. } But it is unresponsive, so I tried using the run loop instead. void delayWithRunLoop(NSTimeInterval interval) {

Autolayout: NSStackView won't resize parent view when height dynamically changed

≯℡__Kan透↙ 提交于 2020-01-13 21:37:47
问题 Similar question: How to resize a parent view based on the size of subviews layouted with Autolayout I got an NSStackView which loads DisclosureViewController s (NSViewController subclasses) just like in the Apple Example InfoBarStackView. Those can expand and retract views of arbitrary height. I would like the parent view containing the NSStackView to resize its height according to the contents of the NSStackView . In the Apple example that works. However, unfortunately, Apple is resizing a

Determine NSDate for Memorial Day in a given year

柔情痞子 提交于 2020-01-13 20:16:47
问题 Is there a better way to determine the NSDate for Memorial Day (the last Monday in May) in a given year? NSInteger aGivenYear = 2013 ; NSCalendar* calendar = [NSCalendar currentCalendar] ; NSDateComponents* firstMondayInJuneComponents = [NSDateComponents new] ; firstMondayInJuneComponents.month = 6 ; // Thanks, Martin R., for pointing out that `weekOfMonth` is wrong for returning the first Monday in June. firstMondayInJuneComponents.weekOfMonth = 1 ; firstMondayInJuneComponents.weekday = 2 ;

What are the correct bindings for an NSComboBox for use with Core Data

谁说胖子不能爱 提交于 2020-01-13 19:25:05
问题 Imagine if you will a Core Data app with two entities (Employee, and Department). Employees have a to-one relationship with department (department) and the inverse is a to-many relationship (employees). In the UI you can select individual Employee entities and edit the details in a detail area (there are of course other attributes and there is UI for adding and editing Department entities). When using a popup button the bindings are: content = PopUpArrayController.arrangedObjects content

How can I create a document-based application that cannot create a new document?

China☆狼群 提交于 2020-01-13 19:11:50
问题 I have a document-based application that is designed to process existing documents, not to create new documents. How do I prevent the application from creating a new, blank document when launched by opening it from the Finder? 回答1: There is an NSApplication delegate protocol method you can implement. - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender { return NO; } Here's the documentation 回答2: Depending on what you are specifically doing, you might want to override newDocument