cocoa

NSTokenField: different colors for tokens

被刻印的时光 ゝ 提交于 2021-02-08 05:19:13
问题 I have created an NSTokenField in my xib. I'd like to display tokens with different colors inside that tokenField. Meaning: some tokens will be blue, the rest will be red (according to their content). Is that possible? The following code doesn't work for me. I hope someone can help me out: - (id)tokenField:(NSTokenField *)tokenField representedObjectForEditingString:(NSString *)editingString { id returnRepresentedObject = nil; NSTokenFieldCell *tf = [[NSTokenFieldCell alloc] init]; tf

Swift NSWindow shows up and disappears immediately

家住魔仙堡 提交于 2021-02-08 04:57:17
问题 I'm a complete beginner to Swift, so this may be a silly question, but I can't figure out how this works... I have a view with a button inside which calls the following code: let window = NSWindow() window.center() window.title = "test" window.makeKeyAndOrderFront(self) When I click the button the window opens just for a moment and disappears a few milliseconds later. Can anyone help me with that? It seems I have a quite serious misunderstanding about views in Cocoa ;-) Thanks Tom 回答1: The

Synthesized Properties and ivar error

£可爱£侵袭症+ 提交于 2021-02-07 18:11:09
问题 I've been building my program in the "Debug X86-64" mode (Xcode 3.6) and everything works flawlessly. However, I just tried switching to "Release X86-64" mode and upon compiling received the following errors for each of my properties: Synthesized property 'x' must either be named the same as a compatible ivar or must explicitly name an ivar. Where 'x' is one of my properties, the first being 'company' (I received 51 errors of this type.). In my .h interface file, I've listed the items this

Running performSelector: on an object that returns a double, not id

£可爱£侵袭症+ 提交于 2021-02-07 14:40:40
问题 How can I run an arbitrary selector on an object, the return of which is a double? For example, I have obj A, which has method -(double)blah; How can I do double res = [obj performSelector:@selector(blah)]; ? performSelector returns an id type object, so should I cast from id to NSInteger to double - that will lose precision? Also, I do not want to use the obj's methodSignatureForSelector (meaning, no NSMethodSignature and no NSInvocation ) because it is a huge CPU drain at run-time. 回答1: You

Running performSelector: on an object that returns a double, not id

纵饮孤独 提交于 2021-02-07 14:36:36
问题 How can I run an arbitrary selector on an object, the return of which is a double? For example, I have obj A, which has method -(double)blah; How can I do double res = [obj performSelector:@selector(blah)]; ? performSelector returns an id type object, so should I cast from id to NSInteger to double - that will lose precision? Also, I do not want to use the obj's methodSignatureForSelector (meaning, no NSMethodSignature and no NSInvocation ) because it is a huge CPU drain at run-time. 回答1: You

How do I use Apple's GameController framework from a macOS Command Line Tool?

十年热恋 提交于 2021-02-07 13:56:17
问题 I'm trying to get the following code to work as a macOS command line tool. It is important that this not be a Cocoa app, so that is not an option. This same code works perfectly in the same project with a Cocoa App target and detects a compatible controller, but when run as a Command Line Tool target, nothing happens and the API shows no controllers connected. Obviously, some of it is contrived... it's just the simplest I could boil it down to and have some indication of things happening when

Show Window without activating (keep application below it active)

こ雲淡風輕ζ 提交于 2021-02-07 13:10:05
问题 I need to show a window (without title bar) above third party applications without my window taking focus. I have tried using an NSPanel and setting enabling non-activating, but that didn't help. I tried orderFront:self , but that didn't help either. I always needed to add [NSApp activateIgnoringOtherApps:YES]; because the window wouldn't show otherwise. I have here a sample project for just this functionality: http://users.telenet.be/prullen/TopW2.zip UIElement is set to true in the

Show Window without activating (keep application below it active)

妖精的绣舞 提交于 2021-02-07 13:07:13
问题 I need to show a window (without title bar) above third party applications without my window taking focus. I have tried using an NSPanel and setting enabling non-activating, but that didn't help. I tried orderFront:self , but that didn't help either. I always needed to add [NSApp activateIgnoringOtherApps:YES]; because the window wouldn't show otherwise. I have here a sample project for just this functionality: http://users.telenet.be/prullen/TopW2.zip UIElement is set to true in the

How to set custom HTTP headers to requests made by a WKWebView

天涯浪子 提交于 2021-02-07 12:05:58
问题 I have built an app that includes a WKWebView, and the website that the web view loads supports multiple languages. How can I change the Accept-Language header in a WKWebView, or other HTTP headers for that matter? 回答1: I've got it working in a way, but only get requests will have the custom header. As jbelkins answered in the linked so from Gabriel Cartiers comment to your question, you will have to manipulate the request and load it anew. I've got it working for GET-Requests like this: (it

How can I get a reference to the current UINavigationController?

℡╲_俬逩灬. 提交于 2021-02-07 11:23:08
问题 In Objective-C, what is the best way of getting a reference to the current UINavigationController? I would like to gain access to it from any class that may not have a reference to a UIController, delegate, or anything else. Is there an existing way to get the current UINavigationController? Should I add something to my application delegate, and retrieve that? 回答1: As it turns out, you can get it, albeit with quite a bit of dot syntax, from any UIView/UIViewController descendant. self.(view)