Note that there are some explanatory texts on larger screens.

plurals
  1. POColorWell for Colored "Category"
    primarykey
    data
    text
    <p>I have an <code>NSTextField</code>, an <code>NSTableView</code> with a column "category", an <code>NSColorWell</code>, and a custom array controller.</p> <p>The <code>NSTextField</code> and the column "category" from the <code>NSTextField</code> are bound to the array controller so that everything I write in the text field shows up in this column.</p> <p>The problem I have is the following:</p> <p>I want the the string in the "category" column to get the color of the <code>NSColorWell</code> when the user chooses a color. All that works fine, but when I open the app a second time and I create a second entry, then the color of the string in the "category" column goes back to the first color it had before the user chose a color.</p> <p>The way I'm trying this at the moment:</p> <p>AppDelegate.h :</p> <pre><code>IBOutlet NSArrayController *doToItemsArrayController; NSColorWell *colorWell; - (IBAction)addNewToDoItem:(id)sender; @property (assign) IBOutlet NSColorWell *colorWell; </code></pre> <p>AppDelegate.m :</p> <pre><code>@synthesize colorWell; - (IBAction)addNewToDoItem:(id)sender { ToDoItem *newToDo = [[ToDoItem alloc] init]; [newToDo setCategory:@"Beispiel-Kategorie"]; [newToDo setColor:[NSColor greenColor]]; [doToItemsArrayController addObject:newToDo]; } - (IBAction)colorWellColorChanged:(id)sender { NSColor *currentColor = [colorWell color]; NSArray *selectedItems = [doToItemsArrayController selectedObjects]; // Allen Items die Farbe geben // Es können ja auch mehrere ausgewählt sein. for (int i = 0; i &lt; [selectedItems count] ; i++) { [[selectedItems objectAtIndex:i] setColor:currentColor]; } } </code></pre> <p>ToDoItem.h : </p> <pre><code>NSString *category; NSColor *color; @property (retain) NSString *category; @property (retain) NSColor *color; </code></pre> <p>ToDoItem.m : </p> <pre><code>@synthesize category; @synthesize color; - (id)init { self = [super init]; if (self) { color = [NSColor redColor]; } return self; } - (id)initWithCoder:(NSCoder *)decoder { if(![super init]) return nil; [self setCategory:[decoder decodeObjectForKey:@"category"]]; [self setColor:[decoder decodeObjectForKey:@"color"]]; return self; } - (void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeObject:[self category] forKey:@"category"]; [encoder encodeObject:[self color] forKey:@"color"]; } </code></pre> <p>I hope my code will help you to understand my problem and to get this working.</p> <p>I look forward to hearing from you. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload