Cocoa How should a custom view update a model object?

This is a Cocoa n00b question - I've been programming GUI applications for years in other environments, but now I would like to understand what is "idiomatic Cocoa" for the following trivialized situation: I have a simple custom NSView that allows the user to draw simple shapes within it. Its drawRect implementation is like this: - (void)drawRect:(NSRect)rect { // Draw a white background. [[NSColor whiteColor] set]; NSRect bounds = [self bounds]; [NSBezierPath fillRect:bounds];

Cocoa Clickable url link in NSTextFieldCell inside NSTableView?

I have a NSAttributedString that I'm using in a NSTextFieldCell. It makes several clickable url links and puts a big NSAttributedString inside the NSTextFieldCell. Whenever I am viewing the NSTextFieldCell normally and it's highlighted, I cannot click on the links. If I set the TableView so I can edit each column or row, when I click twice, go into Edit mode and view the NSTextFieldCell contents, my links show up and are clickable. When I click away from the row, I can no longer see clickable l

Cocoa I want to allocate memory for 700 MB to 800 MB Image size

I am trying to allocate memory NSImage*originalLocationImage; NSURL *fileURL = [NSURL fileURLWithPath:originalLocation]; //originalLocation is file path in my disk originalLocationImage = [[NSImage alloc]initByReferencingURL:fileURL]; NSBitmapImageRep *sourceRep = [[NSBitmapImageRep alloc]initWithData:[SourceImage TIFFRepresentation]] //this line fails to allocate memory and it fails for large Images/ and throws error malloc: *** mmap(size=268435456) failed (error code=12) *** error: c

Cocoa SFAuthorizationView authorize: method does not work

I've got an SFAuthoizationView I'm using in my app and I'm trying to call the authorize method from my code to prompt the user to authorize if they currently are not authorized. My issue is that this method does not seem to work! My code is as follows, where authView is the SFAuthorizationView and authorizeMe is the method that gets called when a button is clicked (and the log message does show, so I know it's getting called). If the lock is locked the authorize message just returns false and

Cocoa Objective C Printing: How to set header content?

I want to print a specific NSView. When I do this, I wish to add content to the header of the print page. e.g. If the NSView contains a picture of a cat, when I press print, print preview shows up with the picture of the cat. I want the print out to be a picture of a cat, with the caption: "Cat" in the header, which I do not want visible on the original NSView. Also, if this is possible, is it also possible to add images too? Thanks!

Cocoa Why can't code inside unit tests find bundle resources?

Some code I am unit testing needs to load a resource file. It contains the following line: NSString *path = [[NSBundle mainBundle] pathForResource:@"foo" ofType:@"txt"]; In the app it runs just fine, but when run by the unit testing framework pathForResource: returns nil, meaning it could not locate foo.txt. I've made sure that foo.txt is included in the Copy Bundle Resources build phase of the unit test target, so why can't it find the file?

Cocoa Disable colour change when source list loses focus

When an item is selected in the source list it is highlighted in blue. When another element on the window is selected, however, the highlight becomes a lighter blue as the source list is no longer focused. I would like to change the behaviour so the item is always the darker blue, the same behaviour as seen in Finder.

Cocoa NSTask executed only once

I'm having trouble executing different NSTask's. Same launchPath, different arguments. I have a class who's instances administer own NSTask objects and depending on arguments those instances were initialized with - dependent NSTask object is being created. I have two initializers: // Method for finished task - (void)taskFinished:(NSNotification *)aNotification { [myTask release]; myTask = nil; [self createTask]; } // Designated initializer - (id) init { self = [super init]; if (self

Cocoa Nstableview group style for nsoutlineview

I like the look of the group rows in the nstableview. In apple mail, the group sections like mailboxes and rss with that style too. Is there an easy way to make a group row or root item in an nsoutlineview to look like that? I think I have to override the willDisplayCell method...

Cocoa NSPredicateEditor Just Won't Show Up

I'm having a really weird problem. I'm trying to put an NSPredicateEditor into my interface using IB, and when I build the app it just shows up as an empty gray rectangle. This is without my applying ANY CHANGES WHATSOEVER to the defaults, including not modifying the default templates. What could possibly be going on?

Premade Cocoa component for a UI control like this? (rounded rectangle showing a stack of items)

Luckily, the code that WebKit uses to make this control draws onto a canvas using basic drawing operations, so it shouldn't be too hard to convert into a Cocoa control. This is what I have so far:Development progress so far I'll update here again once I get it finished. Original question I don't know what to call this sort of control, so I'll show pictures (from the iTunes dialog for a media player and the WebKit Web Inspecto

UISlider in Cocoa

In a Cocoa app I added a UISlider. If I run the program without adding any code then I can drag the slider left and right. However, if I assign an IBOutlet to it, once I touch the slider, the application exits. Why is that?

Cocoa Problem with negative date on iPad and not on simulator

I'm working on an history application so I need to cope with date before and after JC. I'm trying to parse a string with the form "01/01/-200" but it returns a null date while it's working with "01/01/200". Here is my code : NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc]init] autorelease]; [dateFormatter setDateFormat:@"dd/MM/y"]; // @TODO Get negative date [dateFormatter setLenient:NO]; NSDate* date = [dateFormatter dateFromString:dateString]; return date; I also try using wit

Cocoa calling action obtained from button

I have following requirements: Obtain action associated with NSButton using : - (SEL)action Call the obtained action. Can we perform 2nd pt. Generally we invoke an action like this- [self abc:nil] just thinking if we can invoke the method obtained from 2nd pt. in same way!

Cocoa Autorelease pools in appkit applications

I'm having difficulties to understand exactly WHEN autorelease pools are created and released in AppKit apps. For example, if I have an ApplicationController class that overrides init, is there an autorelease pool that gets created before it starts and gets drained after it ends?

Saving a binary file in custom location in Cocoa

My Cocoa app saves data to a random location ( say /tmp) and once the user is done editing this file and say, hits " Done Editing", I want to prompt the user to save a file in a location of his choice. Any pointers on how to accomplish this in Cocoa ? Thanks in advance.

Cocoa: Passing texture atlas values to a NSView

I'm passing values to a method in a NSView subclass - I'm calling it twice but the drawRect method is only showing the last value passed...the values are coordinates on a texture atlas, not sure if that is clear so here's my code: in my AppController.m: - (IBAction)setCards:(id)sender { //get window frame for positioning NSRect winFrame = [[NSApp mainWindow] frame]; //add back shields float backArrowX = (winFrame.size.width/2)-90; float backArrowY = (winFrame.size.heigh

Cocoa leaks enabling and disabling runAtStartupEnabled

I just wanted to ask if you see some leaks here: + (BOOL)runAtStartupEnabled { NSURL *itemURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; Boolean foundIt=false; LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL); if (loginItems) { UInt32 seed = 0U; NSArray *currentLoginItems = [NSMakeCollectable(LSSharedFileListCopySnapshot(loginItems, &seed)) autorelease]; for (id itemObject i

Cocoa From a NSSegmentedControl to a label

I'm new to Mac Programming, but i'm having some ideas for an application. My question is: i have a NSSegmentedControl with 2 cells and i wanted to, if the cell number 1 is selected, write something on a label with, for example, a blue color. How can i do this? i'm sorry if this was already asked :/

Cocoa Drawing YUV frames with OpenGL on mac

I'm decoding video with ffmpeg libraries and store decoded frames in array. Now i want to draw these frames on the screen with OpenGL. I googled and found that apple offers to use GL_APPLE_ycbcr_422 format for effective drawing. So i switched decoding frames in ffmpeg to PIX_FMT_YUYV422 format (packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr) which seems to be an equivalent of GL_APPLE_ycbcr_422 in OpenGL. Now i'm trying to draw frames on surface with this code: GLsizei width = 2, height = 2; uint8_t data

Get Relative Path in Cocoa

I would like to get relative path in cocoa app. ex. Input: /Users/foo/bar/sample.txt Base path: /Users/foo Expected output: bar/sample.txt How can I get this?

Cocoa Retrieving correct timestamp for image in Aperture

A question for the Aperture and Cocoa developers out there… I use Aperture and @Fraser Speirs' FlickrExport plugin to manage my photos and upload them to Flickr. FlickrExport sets custom tags in Aperture with the Flickr photo ID (among other things), so that you can see which images have been exported. I also post photos directly to Flickr from my iPhone via email (the only way I've found to keep the EXIF data intact). I'm trying to whip up a Python script that will poll my Flickr stream and

Cocoa Implementing a basic Source List using NSOutlineView and NSTableCellView

I am new to Cocoa, but am an experienced programmer (mostly C, C++, .NET and QT). I am working on implementing a Source List which is the sidebar you typically see in finder and iTunes. I am attempting to do so using a very basic test case. So no CoreData, no TreeController, etc... I implemented the NSOutlineViewDataSource. Here is my code: @implementation OutlineViewDataSource - (id)init { self = [super init]; if (self) { header = [[NSString alloc] initWithString: @"Header"

Cocoa warning: comparison is always true due to limited range of data type causes crash

I have a warning that I am unable to find the cause of. I am following instructional code in a text on Cocoa programming that implements a document based image slide show. This warning causes a while loop to be executed more than the correct number of times which causes the program to crash. The code downloaded from the author's website does not have this problem. I assumed it was a simple matter of a typo in my version but carefully reading both versions of code I was unable to come acros

Cocoa Simple file reader wont work

I trying to learn Xcode, Cocoa, Objective C. Today I thought I was going to make a simple app the uses the Nac file browser, reads the file and displays it in an NSTevtView. Everything acts like it wants to work but the file never displays. If I debug it, it shows my string has the file contents but I can't get it to display to the TextView. Here is my code, OpenUp.h and OpenUp.m #import <Foundation/Foundation.h> @interface OpenUp : NSObject { NSString *reader; IBOutlet NSTextF

Cocoa What is the correct way to call IBAction from different controller?

It's about objective c and cocoa I've faced a problem and don't know how to solve it. Hope I can find answer here and it will be helpful for some other programmers. So, I have a simple window with 4 elements: NSTextField - first field to set value NSButton - to set value in first field NSTextField - second field to set value NSButton - to set value in second field here is "controller 1" code: #import "controller2.h" @interface controller1 : NSControl{ IBOutlet NSTextField * text1; } -(

Cocoa Creating NSToolbar style buttons

Is there a bevel style that can replicate NSToolbar style of buttons that are used, for instance, in the Safari's preferences window to switch between different panes? I need to replicate NSToolbar in an NSView using NSButtons. I understand that I should probably be using NSTabView, but I'd like to implement the look of xcode's left pane. Any tips here would be appreciated greatly.

Cocoa Drawing a Subview on top of a Google Map Displayed in a WebView on OSX

I'm trying to make a simple utility in OSX that renders a Google Map in a WebView and displays some views on top of it. For most websites, including links to, the subviews will render on top of the WebView. Sweet. But if I use the Google Maps API v3, for some reason the map content will render over my subviews. Here's an example: I have a window with two subviews, a WebView, and an NSButton. The order is such that the button should be on top. I placed the button so half

Cocoa Finder like coloured labels

OS X Finder has this nice feature to colour-label files. I'm thinking of using a similar feature in my app (that is: use this in an NSTableView/NSOutlineView, not looking to highlight items in Finder from my app). Is this ability somehow available through any of the default user interface classes or would it require a custom implementation? I have experimented with setting NSTextFieldBezelStyle to NSTextFieldRoundedBezel but this seems to kill the ability to draw a background colour and also de

Cocoa How to avoid copy and pasting?

I'd like to improve this method if possible: this is a small section whereby all of the textfield (eyepiece, objectivelenses etc) texts are saved. Unfortunately, having to do this lots of times for each part of my app is prone to error so I would like to improve it. I'm thinking some sort of fast enumeration with arguments for the method being the textfields etc. and I can have all the keys in a dictionary (which is already set up). Just a pointer to the right docs or, perhaps, some sort of p

Cocoa Unwanted padding in CATextLayer

I am having a problem of drawing a character in a CATextLayer such that the layer is exactly the size of the character. I use the code below to get the size of the glyph corresponding to the character in the string. At the moment I am neglecting diacretics, so that I am assuming that there is a one to one correlation between glyphs and characters. I also get nice bounding box values for several characters for the Helvetica font at size 128pt: Character | x | y | width | height | B

Cocoa Focus ring on NSPopupButton doesn't appear on pressing tab

I have a couple of NSPopupButtons on my view and they are defined as a newKeyView after one of the text fields. The problem is that somehow they are not getting the focus ring when pressing the tab button comes to them, like they are ignored. What should be done in order for them to get a focus ring? Thanks, Nava

Cocoa program can't be stopped

I'm trying to write an OS X app that uses a serial port. I found an example (cocoa) and got it running in Xcode 4. On the first run, it opens the port and I'm able to exchange data with the hardware. If I try to change the port the program goes rogue. The pinwheel starts and the UI is unresponsive. I can't stop the program from Xcode, nor can I kill it from Terminal, or Force Quit. Force Quit of Xcode doesn't do it. Although the PID goes away with a kill from Terminal, the UI is still present w

Cocoa NSPopupButton in view based NSTableView: getting bindings to work

I'm trying to achieve something that should be simple and fairly common: having a bindings populated NSPopupButton inside bindings populated NSTableView. Apple describes this for a cell based table in the their documentation Implementing To-One Relationships Using Pop-Up Menus and it looks like this: I can't get this to work for a view based table. The "Author" popup won't populate itself no matter what I do. I have two array controllers, one for the items in the table (Items) and one for t

Cocoa How do I post-process a control’s input, and update all attendant controls?

I’m working on a little optical-illusion app. As part of that, I have a model key (a CGFloat) representing an angle. I have three controls — an NSTextField, an NSStepper, and an NSSlider — each bound to that model key. (The NSTextField was created as a “Text Field with Number Formatter”.) I want that angle to fall between -45 and 45 degrees at all times. I also want it rounded to the nearest integer. To that end, I’ve implemented a setAngle method that applies those rules. In addition to roun

Cocoa How to make OSX Yosemite webviews work with ADFS

I'm using a webview to host a log in page that redirects to an ADFS server to offer single sign on. This works on 10.9, but I noticed for OSX 10.10 I am able to get to the point where the ADFS server will present an http authentication challenge, the webview will show the default dialog to enter credentials, but after entering the credentials I never see the expected redirects that eventually allow the single sign on process to complete. Even if I cancel the webview prompt to login, I never rece

Cocoa Listen for Deleting of Line in NSTextView

How do I detect when a line (i.e. a "\n" character) is deleted in an NSTextView? I can easily listen for new lines using textView:doCommandBySelector: and listening for "insertNewLine:". (See here) I can also detect deletion of characters using the same method but instead listening for "deleteBackward:". However, I am not sure how to find out what character is being deleted, and therefore perform an action only when a "\n" character is deleted. Can anyone point me to the right method to do this?

Cocoa UI testing with AVPlayer

I'm looking for a way to test my application that use an AVPlayer. How can I load a video file? I tried to record the manipulation but recording stop when calling NSOpenPanel.runModal(). Any idea?

Cocoa NSAnimationContext completion parameter?

My animation can be performed on several different similar views (managed in an array), but the completion handler does not take a parameter. How then can I tell at completion time which animation I am completing? The following its used to animate the frame of one (of several) sectionViews. When the animation is finished, I need to be able to send a notice to the particular sectionView. NSLog(@"Animation started"); [NSAnimationContext beginGrouping]; [[NSAnimationContext currentContext] setDu

Is this the correct way to implement scaled printing in Cocoa?

I am trying to implement printing in my new Cocoa application. Everything has been working fine for a while except for scaling, i.e. printing at 75%, 125%, etc. As far as I can tell from the Apple docs, the program supposed to adjust the rectangle returned from the rectForPage: method depending on the scale factor. I found some sample Apple code that appeared to work this way, and an old post on cocoabuilder.

Cocoa swift: how can set NSTextField to only accept number

Any of you knows how can set NSTextField to only accept numbers(int)? Let me explain. I got my NSTextField: @IBOutlet weak var txtBoxField: NSTextField! But I can type any string and what I want is just to be able to type numbers. I'll really appreciate your help.

  1    2   3   4   5   6  ... 下一页 最后一页 共 43 页