cocoa

Core Animation Unwanted Text Sharpening.

Whenever I add a layer for Core Animation either from the nib or programatically, the NSTextFields (labels) in my interface get messed up. Here's a screenshot from Apple's BasicCocoaAnimations example. (Look at the text fields on the left, somehow they're drawn sharper than normal) Note that if I add a layer in IB then it also gets mess...

How do I write an IF ELSE to check string contents of an array?

I'm trying to write an IF ELSE statement to enable shipping, If user doesn't add an address the array contents remain as "-" & "-" for the two items in the array. I want to check to see if those are in the array, if they are then I want to enableshipping. Here is the code for getting the array: NSArray *paths = NSSearchPathForDirector...

Keeping window of another application active while still receiving mouse events from another app's window?

Is there a way to have my app's window receive keyboard and/or mouse events (i.e. user clicking on window's buttons) while still retaining focus to another, unrelated app? I've tried configuring my window at different levels, including [myWindow setLevel:NSPopUpMenuWindowLevel] to no avail. ...

Custom Cocoa Framework and a problem using it

Hello, I made a custom cocoa framework just to experiment and find the best way to make one but ran in to a problem using it. The framework project builds and compiles just fine, but when I use it in an xcode project I get the error, 'LogTest' undeclared. The name of the framework is LogTest Heres the code to my app that uses the frame...

Is this a good KVO-compliant way to model a mutable to-many relationship?

Say I'd like a mutable, unordered to-many relationship. For internal optimization reasons, it'd be best to store this in an NSMutableDictionary rather than an NSMutableSet. But I'd like to keep that implementation detail private. I'd also like to provide some KVO-compliant accessors, so: - (NSSet*)things; - (NSUInteger)countOfThings; -...

Scan from last instance of character to end of string using NSScanner

Given a string such as: "new/path - path/path/03 - filename.ext", how can I use NSScanner (or any other approach) to return the substring from the last "/" to the end of the string, i.e., "03 - filename.ext"? The code I've been trying to start with is: while ([fileScanner isAtEnd] == NO){ slashPresent = [fileScanner scanUpToString:...

What's the proper way to setup different objects as delegates using Interface Builder?

Let's say I create a new project. I now add two text fields to the view controller in Interface Builder. I want to respond to delegate events that the text fields create, however, I don't want to have the main view controller to act as the delegate for both text fields. Ideally I want a separate file for each text field that acts as the ...

What to subclass for clickedRow (NSTableView)

Which method should I subclass to change the drawing when a row is right-mouse clicked? (I want to change it in selecting the row). ...

NSScrollView - pattern background - how to start from top-left corner?

To fill NSScrollview with pattern image I use - (void)setBackgroundColor:(NSColor *)aColor method where aColor is created with + (NSColor *)colorWithPatternImage:(NSImage *)image method. Despite of what isFlipped returns for NSScrollView and its content view, pattern start repeat from bottom-left corner while I want it to start from top-...

NSTableView and NSSearchField in an NSView, which is the outlet of an NSMenuItem, don't work

I'm having an NSView, which is set as the view: outlet of an NSMenuItem. The view contains an NSTableView (inside an NSScrollView) and an NSSearchField. The NSMenu is shown when the user clicks a specific NSStatusItem. When I launch the application from Xcode (Build and Run), the controls behave well, but whenever I launch it from the Fi...

Where should document-related actions for a Cocoa app be implemented?

I'm writing a document-based Cocoa app that's basically a graphical editing program. I want the user to be able to show/hide non-modal windows (such as an inspector window). Since these windows would be shown/hidden from menu items, where is the "best" place to implement the actions, such as - (IBAction)toggleInspector:(id)sender? I'v...

How can I make the Tab key move focus out of a NSTextView?

I'm using an NSTextView to allow multi-line input. However, due to the nature of my app, users will be more comfortable moving to the next input element when they press TAB. How can I make TAB exit the NSTextView, while keeping the newline behaviour of the Enter key? ...

How to allow one thread to mutate an array property while another thread iterates on a copy of the array

I would like to implement an observer pattern in Objective-C where the observer implements an interface similar to SKPaymentTransactionObserver and the observable class just extends my base observable. My observable class looks something like what is below. Notice I'm making copies of the observers before enumeration to avoid throwing ...

How can my code get notified when the user pastes or drags an image into NSImageView?

I have an instance of NSImageView. I have told InterfaceBuilder to allow the user to paste or drag an image into this view. This works. However, I don't see a way in the NSImageView or related documentation to get notified when this actually happens. I was expecting a delegate or some such, but I have been unable to find it. Any ideas? ...

NSMenuItem not responding to setIndentationLevel:

If I call setIndentationLevel: on an NSMenuItem then nothing happens, if I call indentationLevel on it after I set it to 3, it returns 3 like it should. I'm adding the menu items to the Dock menu and I don't see anything changing. NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle: @"title" action: nil keyEquivalent: @""]; [menuIt...

How to store enum values in a NSMutableArray

My problem is since an enum in objective-c essentially is an int value, I am not able to store it in a NSMutableArray. Apparently NSMutableArray won't take any c-data types like an int. Is there any common way to achieve this ? typedef enum { green, blue, red } MyColors; NSMutableArray *list = [[NSMutableArray alloc] i...

Multiple undo managers for a text view

Hi, I've a text view that gets its content from an attributed string stored in a model object. I list several of these model objects in a drawer and when the user clicks on one the text view swaps its content. I now need to also swap the undo manager for the text view. I initialise an undo manager on my model object and use undoManager...

How to set up a user Quartz2D coordinate system with scaling that avoids fuzzy drawing?

This topic has been scratched once or twice, but I am still puzzled. And Google was not friendly either. Since Quartz allows for arbitrary coordinate systems using affine transforms, I want to be able to draw things such as floorplans using real-life coordinate, e.g. feet. So basically, for the sake of an example, I want to scale the v...

Proper way to return an array

Hey there, I never seem to get this right. I've got a method that returns a mutable array. What is the proper way to return the array and avoid potential memory leaks? If I plan to store the results locally inside another view controller, does that affect the way the array should be returned? Lastly, what if it's just an non-mutable...

XIB-instantiated Object's IBOutlet is nil

I have a XIB set up like in this screenshot: File's owner is my main window controller. The XIB is also in charge of creating an object that serves as the delegate for the MGScopeBar view. As you can see in the screenshot, the scope bar delegate has an IBOutlet for the search field so that it can return it as an extra view as part of ...