osx,cocoa,colors,nstableview,highlight , Cocoa osx NSTableview change row highlight color

Cocoa osx NSTableview change row highlight color


Tag: osx,cocoa,colors,nstableview,highlight

In my application I have a view based NSTableView with one column. The highlight color of the rows is set to regular (blue). I need to change that color to my custom color. In the interface builder I tried changing it but the only options are "None, regular and source list".

I tried this post solution with no success: http://stackoverflow.com/a/9594543/3065901

I read that I have to use this delegate method but I dont know how to use this.

- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row

I tried drawing the row in that method but i get invalid context warnings and the row still keeps with the same higlight. Please post a simple example of how to use this delegate method:

Need help please. Thanks in advance.


From this link.


#import <Cocoa/Cocoa.h>
@interface MyNSTableRowView : NSTableRowView


#import "MyNSTableRowView.h"

@implementation MyNSTableRowView
- (id)init
    if (!(self = [super init])) return nil;
    return self;

- (void)drawSelectionInRect:(NSRect)dirtyRect {
     if (self.selectionHighlightStyle !=    NSTableViewSelectionHighlightStyleNone) {
     NSRect selectionRect = NSInsetRect(self.bounds, 2.5, 2.5);
     [[NSColor colorWithCalibratedWhite:.65 alpha:1.0] setStroke];
     [[NSColor colorWithCalibratedWhite:.82 alpha:1.0] setFill];
     NSBezierPath *selectionPath = [NSBezierPath bezierPathWithRoundedRect:selectionRect
                                                               xRadius:6 yRadius:6];
     [selectionPath fill];
     [selectionPath stroke];


- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row
     MyNSTableRowView *rowView = [[MyNSTableRowView alloc]init];
     return rowView;


best way to create a mat from a CIImage?

I am using CIDetector to detect faces, then using OpenCV on the lower half of each face to detect the size of any smiles. I am using the below code to create the cv::mat which OpenCV can perform the detection on, as you can see the image goes through the...

How to get NSTableView to use a custom cell view mixed with preset cell views?

I have a NSTableView configured in Interface Builder which uses several default cell views. However the first column's cell view needs to be created from a custom class. How do I implement NSTableViewDataSource method tableView.viewForTableColumn() so that it creates the default cell views for the remaining columns? Here's my method...

CGDisplayCopyAllDisplayModes leaves out one valid mode

When programmatically working with display modes in OS X (documentation), I've found that the CGDisplayCopyAllDisplayModes leaves out the rightmost option that is presented in System Preferences. A simple utility that prints the size of the current display mode and all available display mode sizes outputs this current size: 1920x1200 available...

Initializing a xib view as a subview of another NSView

I'm trying to learn OSX development, and I've created a view in a .xib file, and I'm trying to initialize and then add this view as a subview. I've googled how to do this, and all of the solutions are for iOS and use a call such as MyViewClass* myViewObject...

Please help protocol code that does not make sense

i'm stumped with part of this statement: @property(nonatomic, readonly) NSArray <id<NSFetchedResultsSectionInfo>>*sections this property belongs to NSFetchedResultsController Class. although NSFetchedResultsSectionInfo is a protocol, id<NSFetchedResultsSectionInfo> is an object type that must conform to the NSFetchedResultsSectionInfo protocol. id<NSFetchedResultsSectionInfo> is not a protocol so enclosing them in angle brackets <id<NSFetchedResultsSectionInfo>> makes no sense. the...

Crash when processing `__Atom` class object in Objective C (using Objective C runtime )

Hi I'm using this answer to get list of class to automatically build some structure. My code looks like that: NSMutableDictionary *result = [NSMutableDictionary dictionaryWithCapacity: 32]; Class* classes = NULL; int numClasses = objc_getClassList(NULL, 0); if (numClasses > 0 ) { classes = (Class*)malloc(sizeof(Class) * numClasses); numClasses = objc_getClassList(classes, numClasses);...

Mac OSX - Allow for user input in shell script via GUI or Prompt

first time post so please let me know how I could improve.. I created a shell script which requires a person to input their name and then generates a report. The script works as needed when chmod'd into an executable script and run from terminal. But, I would like to...

Run Boot2Docker from bash

I have installed Boot2Docker on my Mac. By clicking on the app icon, a terminal window opens with some bash script running to prepare the docker vm and then you're good to go. My problem is, I want to write a bash script to run the Boot2Docker vm and then...

How to display Apple San Francisco's numbers mono-spaced rather than proportionally?

I've recently installed El Capitan on OSX, which comes with the new San Franciso font as system font. The apple presentation here https://developer.apple.com/videos/wwdc/2015/?id=804 (Bit of an overview here: http://codemotionapps.com/san-francisco-display-vs-text-compact-vs-normal-a-brief-review/) states that, by default, numbers are displayed proportionally. They do allow to switch to displaying them mono-spaced (at least in their...

Command-Line Testing Using Cocoa Touch

I have developed several test for an application, and I would like to run this application using the command-line. I have read this tutorial; however, I haven't been able to run them. When executing the following command: xcodebuild test -project MyApplication.xcodeproj -scheme MyApplication -destination 'platform=iOS Simulator,name=iPhone 6' I am getting...

Restrict input on NSTextField

I want to restrict character input on NSTextField, i.e. so that disallowed characters aren't even appearing. Most of what I found about this topic were solutions that only validate after text input finished or using NSFormatter which still allows the character to appear. So far I came up with this...

What is the best way to make sure I am not using any unavailable API's on OSX?

I am writing an OSX app in Xcode 6 but want my application to have support for OSX 10.7 and up. Unfortunately Xcode 6 only includes SDK for 10.10 and 10.9. What is the best way to make sure I am not using any unavailable API's that would crash on...

ffmpeg: wmv files generated on Mac can't be played in Windows

On Mac OS X 10.6.8, I converted a animated gif to a video file in wmv (a requested file format) by using ffmpeg -i File.gif -s 400x400 NewFile.wmv The video file played fine using VLC on Mac. The file can't be played on a Windows 7 machine using the Windows...

Unexpected NSWindow becomes key window

I have a main NSWindow in my application with a button. When the button is pressed it does something like the following: NSWindow *newWindow = [NSWindow initWithContentRect:[screen frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; [newWindow makeKeyAndOrderFront:self]; [self.previousWindow orderOut:self]; This works fine most of the time, but if I have a second window open...

django-admin startproject not working with python3 on OS X

I have python3 installed with Django 1.8.2 on Mac OS. There is also python 2.7 installed by default with the OS. When trying to run startproject I get - $ django-admin startproject mysite Traceback (most recent call last): File "/usr/local/bin/django-admin", line 7, in <module> from django.core.management import execute_from_command_line ImportError: No...

Cursor doesn't update in NSTextField as it autoresizes when resizing the enclosing NSWindow

I have an NSTextField that autoresizes. Its text is centered. When I start typing in the field and then resize the enclosing NSWindow, the cursor stays where it's at rather than repositioning to the appropriate place : I've also made an XCode project demonstrating this problem : https://www.dropbox.com/sh/cohhmslyl9ti43b/AAC6ULteopsQCMDsEArJU15Ta?dl=0 Does anyone...

OSX tmux configuration session open file in vim automatically

So I have tmux and vim running in iterm2 on OSX. I have a tmux.conf file that sources a session in ~/.tmux/ called 'left'. I have successfully loaded this session with three panes. Two panes in a left column and a single pane on the right. I have also managed...

Eclipse CDT - No Console Output on OSX

New to the C++ world and wanted to fiddle around using Eclipse's IDE for C/C++ called CDT. I am on OSX 10.10.2 using eclipse-cpp-luna-SR2-macosx-cocoa-x86_64. Sadly this simple example is not printing anything in the eclipse terminal. #include <iostream> using namespace std; int main() { cout << "Hello World" << endl;...

Display django runserver output from Vagrant guest VM in host Mac notifications?

I can think of many ways to skin this cat, and Googling hasn't shown an elegant solution either. Does anyone have an easy / elegant way to forward the output from Django's runserver command in a terminal connected to a guest Vagrant VM to the host to display to Mac's...

What's the shortcut to interrupt the kernel in Canopy?

I'm on OSX, using canopy. Does anybody know what the shortcut for interrupting the kernel is? Thanks.

How to programatically make a key shortcut?

I'm not even sure if bash is the most proper way to achieve this but, I need to, programmatically, switch between opened applications on OS X. I'm thinking about doing a bash program to execute "cmd+tab". I'm unable to find this on a regular search, so, perhaps someone can point...

Change NSTextField border and BG color while editing

I have a NSTextField that uses no border and window background color while it is displayed but I want it to change to have the default border and white BG color when being edited. I know I can change these properties with: nameTextField.bezeled = true nameTextField.backgroundColor = NSColor.textBackgroundColor() What I...

Stop async operations on window close

In my app delegate I have put the callback to stop the program when the window is shut. func applicationShouldTerminateAfterLastWindowClosed(sender: NSApplication) -> Bool { return true } This doesn't work however because (I assume) there is an async bluetooth task running. What is the best way to stop everything running...

How do you work with views in MainMenu.xib?

I'm coming over from iOS development and I can't figure out this basic thing: if I open MainMenu.xib in Interface Builder and I drag a button onto the main window's view, what class should I connect that button's action to -- the App Delegate? If I want to add a...

iOS : pod update (unable to find the utility “xcode-select”)

xI am a new iOS developer. Recently when I ran "pod update" sth just went wrong see the detail in the following: (unable to find the utility "xcode-select") bash-3.2$ pod install Analyzing dependencies sh: line 1: 4936 Abort trap: 6 /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk / -find xcode-select 2> /dev/null xcrun: error: unable...

Change the “about this” window on mac app

On Macs, there's a default menu at the top for basic application handling functions: I've made an application using Java for my Grade 10 final project, (and I'm quite convinced that it's better than Microsoft Paint) and I decided to package it. Using Eclipse, I exported it as a Mac...

Stuck with creating an event and formatting dates (Swift - EventKit - OS X)

I have been stuck on trying to hardcode a new event. My difficulty lies especially with the dates and formatting let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "MM'/dd'/YYYY" var dateString = "07/16/2015" var startDate = dateFormatter.dateFromString(dateString) var endDate = dateFormatter.dateFromString(dateString) var newEvent : EKEvent = EKEvent(eventStore: store) var error : NSError?...

How to uninstall all python versions and use the default system version of OS X 10.10?

I'm looking for a way to cleanly uninstall all versions of python on OS X 10.10 except the default version that followed with the Mac. How do I proceed? Currently I've some weird behaviour. When typing which -a python I get the following output: /Users/harisfawad/anaconda/bin/python /Library/Frameworks/Python.framework/Versions/2.7/bin/python /usr/local/bin/python /usr/bin/python Why doesn't...

How to get CPU utilization in % in terminal (mac)

Ive seen the same question asked on linux and windows but not mac (terminal). Can anyone tell me how to get the current processor utilization in %, so an example output would be 40%. Thanks

ASP.NET vnext overriding status code set in controller. Is this a bug?

I'm building a simple WebApi in asp.net vnext on a Mac. I've followed the example set in this tutorial but I'm having a problem where the response codes I set in my controller methods are being overridden Take this method in my CrudController: [HttpPost] public void Post([FromBody]CrudObject crudObject) { var...

pcap_dispatch() always returns 0 on Mac OSX for wifi interface

I have few devices connected to wifi router, but pcap_dispatch() always returns 0 for wifi interface while live capturing on Mac OS X. The same code captures response in case of wired interface. Please clarify if I have missed any flag here.

JSON in Python: encoding issue on OS X, no issue on Windows

I have a file log.json that contains one line: {"k":"caf\u00e9"} I run the following code on Windows 7 SP1 x64 Ultimate: import json a = json.load(open('log.json', 'r')) f = open('test.txt', 'w') f.write(a['k']) I don't have any issue. When I run the same code on Max OS X 10.10 x64: Traceback...

Read plist inside ~/Library/Preferences/

I'm trying to access in ~/Library/Preferences/ but my code doesn't work. NSString *resPath = @"~/Library/Preferences/"; NSError *error = nil; NSArray *filenames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resPath error:&error]; if (!error) { for (NSString * filename in filenames) { NSLog(@"%@", filename); } } Maybe I should ask for some permission.. Any idea?...

Use Unix Executable File to Run Shell Script and MPKG File

I have 2 shell scripts and 2 mpkg installer, I am trying to use an unix excitable file to run them all. here is the script I have, but it always has error message "No such file or directory" ? #!/bin/sh # Find the absolute script current path path=$( cd...

Using custom NSValueTransformer subclass with bindings and reverseTransformedValue method

I'm writing a Cocoa App using Bindings. I have a NSSlider as well as a NSTextField. Whereas the Slider's value is bound to the value returned by the transformedValue method, the TextBox should be bound to the reverseTransformedValue method. How may I achieve this? For the Slider I entered the...

Call to implicitly-deleted copy constructor in LLVM(Porting code from windows to mac)

We are in the process of porting some c++ code from windows to mac and are having issues compiling it with LLVM 6.1 using c++11. We are encountering errors all over the place of "Call to implicitly-deleted copy contructor" Some of these errors are popping up in our code. for...

Capitalize all files in a directory using Bash

I have a directory called "Theme_1" and I want to capitalize all the filenames starting with "theme". The first letter of every file name is lowercase and I want it to be upcase. I've tried this but all the letters in the filename are upcase, which is not what I...

NSPredicate crash with path which contains square brackets

I have to search paths which contains square brackets in it from core data. But when I trying to create search query like below, xcode crashes. path == /my/local/[path] I've tried to escape square brackets, from one brackets to 16 brackets, but nothing works. That path is from another application,...

Is it possible to obtain an unique iCloud user ID on cocoa?

My iOS app is currently on beta in TestFlight, and as a way to retribute to the nice people who helped me test it I would like to offer them some goodies such as, for instance, the full final version of the app for free. For this, I was thinking...

Login with Facebook option trigger suggest to download an app

Yesterday I logged in to Airbnb with my Facebook account on my OSX. Shortly later I got a notification both on my iPhone and computer saying "Airbnb is available to install on your iPhone" My question is, does anyone here know how this was done? Is this a feature available...

Set CALayer Gradient Background

I am trying to add a gradient to a CALayer I have created. I can set the background colour of the CALayer with the following: self.colorLayer = [CALayer layer]; [self.colorLayer setBackgroundColor:color.CGColor]; [self.colorView setWantsLayer:YES]; [self.colorView setLayer:self.colorLayer]; I've looked around with no success (surprisingly I thought this would have been answered many...

fatal error: limits.h: No such file or directory

On OSX, I can't compile simple programs from the command-line when I use an externally-provided compiler (e.g. gcc-4.8). System headers like limits.h cannot be found. Example error messages: fatal error: limits.h: No such file or directory Or: fatal error: stdio.h: No such file or directory and so on. What's wrong?...

How can I fix “Error: Formulae found in multiple taps”?

I want to install php54-redis. Yu:nginx Yu$ brew install josegonzalez/php/php54-redis ==> Installing php54-redis from josegonzalez/homebrew-php Error: Formulae found in multiple taps: homebrew/php/php54 josegonzalez/php/php54 Please use the fully-qualified name e.g. homebrew/php/php54 to refer the formula. What am I doing wrong and how is thise done properly?...