Search Results

Search found 26 results on 2 pages for 'nstablecolumn'.

Page 1/2 | 1 2  | Next Page >

  • Sorting NSTableColumn contents

    - by Yahoo
    Hey, I have a problem with sorting NSTableColumn contents. In my NSTableView there are three columns: File, Size, Path. The contents are stored in NSMutableArray. Each object in this array is a NSDictionary containing three keys: file, size and path - value for each is a NSString. In Interface Builder, in each Table Column's attributes I can choose sorting options: Selector: IB entered "compare:" which I think is ok, because I compare NSStrings. Sort Key - and that's the problem I think - I don't know what to enter here. Any clues? If you've got questions about my code, please ask.

    Read the article

  • Sorting NSTableColumn contents

    - by Yahoo
    Hey, I have a problem with sorting NSTableColumn contents. In my NSTableView there are three columns: File, Size, Path. The contents are stored in NSMutableArray. Each object in this array is a NSDictionary containing three keys: file, size and path - value for each is a NSString. In Interface Builder, in each Table Column's attributes I can choose sorting options: Selector: IB entered "compare:" which I think is ok, because I compare NSStrings. Sort Key - and that's the problem I think - I don't know what to enter here. Any clues? If you've got questions about my code, please ask.

    Read the article

  • Force redraw as resizing NSTableColumn in NSTableView?

    - by Dov
    I've implemented - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row in my NSTableView's delegate to resize the height of my table's rows as the width of the leftmost column changes. The problem is that only that column redraws during the resizing (and any column that slide into view during the resize). This results in the funky visual below after resizing. What I'd like is a way to tell the table view to completely redraw while the user is resizing a column. Right now the most I've been able to figure out is calling setNeedsDisplay after it that column finishes resizing.

    Read the article

  • How to get NSFormatter subclass to work with NSTableColumn sort key and selector?

    - by Andrew
    My setup: I have a sqlite database from which I populate a NSMutableArray of NSDictionary objects this is the DataSource for my NSTableView. One of the columns holds "time", the time is a float that holds seconds. I would like to display the values in this column as minutes:seconds. For instance my data would be 123.4329387 I want to display 2:03 which I have no problem doing with a subclass of NSFormatter (or NSNumberFormatter) applied to my NSTextField in the column. I have sorting set up by using the Table Column Attributes in IB, I just have the sort key set to "time" and the selector set to "compare:" which works fine without the formatter. Currently this gives me something like this when I sort (descending) 1:37, 1:31, 0:10, 0:10, 0:09, 1:30, 1:30, 1:26, 0:09 and similar nonsense, it looks like something is going on but it's definitely not sorted. How do I get the sort to look at the underlying data instead of the formatted value? Alternately, how do I specify a custom sort method and where do I put the code for said method? I have searched around quite a bit and have not found anything to help me out with this problem, any help with this is most appreciated.

    Read the article

  • Binding to NSTextField Cell not working, edited value resets to default

    - by cygnus6320
    I'm working on a Core Data document application that dynamically creates NSTableColumns. The data cell type may be a checkbox, slider, etc. Programmatically binding to all cell types works, except for NSTextFieldCell. All NSTextFieldCells fail to bind, and after editing they return to their default value. This happens no matter if they're binding to a string, a number (with an NSNumberFormatter applied), or a date (NSDateFormatter applied). I'm using the following format to do all bindings: NSDictionary *textFieldOpts = [NSDictionary dictionaryWithObjectsAndKeys:@"YES", NSContinuouslyUpdatesValueBindingOption, @"YES", NSValidatesImmediatelyBindingOption, nil]; [aCell bind:@"value" toObject:[[entryAC arrangedObjects] objectAtIndex:0] withKeyPath:@"numberData" options:textFieldOpts]; Again, these statements work if the cell type is anything but an NSTextFieldCell. I threw in an observeValueForKeyPath method to log when the value changes... and for other cell types (NSSliderCell for instance) I can see the value changing, but with the NSTextFieldCell, it never, ever updates. Help!

    Read the article

  • Core Data Image Won't Load Into NSTableView Image Cell

    - by jcady
    In my code I am storing an image into my Core Data model (works fine). If I set up my view to have an NSImageView and bind its Data to Controller Key: selection and modelKeyPath: myImagePath, it works. It will show each image for the selected row. I then create a new column in my NSTableView and drag an image cell onto the column. However, I cannot get my Core Data bindings to have the image show up in the cell. I have tried binding both value and data, but no luck. Since I am sure the image is stored properly, what am I doing wrong in my binding to prevent the image from showing up in the table cell? Thanks so much. (My background: new Cocoa developer who has recently gone through the entire Hillegass book.)

    Read the article

  • NSTableView with columns bound to different NSArrayControllers

    - by Vyacheslav Karpukhin
    i have NSTableView and two columns in it: NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:@"custId"] autorelease]; [column bind:@"value" toObject:arrC2 withKeyPath:@"arrangedObjects.custId" options:nil]; [table addTableColumn:column]; column = [[[NSTableColumn alloc] initWithIdentifier:@"totalGrams"] autorelease]; [column bind:@"value" toObject:valuationArrC withKeyPath:@"arrangedObjects.totalGrams_double" options:nil]; [table addTableColumn:column]; as you can see, columns bound to different NSArrayControllers. first column shows correct values, but second just shows "(" symbol. but if i swap columns like this: NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:@"totalGrams"] autorelease]; [column bind:@"value" toObject:valuationArrC withKeyPath:@"arrangedObjects.totalGrams_double" options:nil]; [table addTableColumn:column]; column = [[[NSTableColumn alloc] initWithIdentifier:@"custId"] autorelease]; [column bind:@"value" toObject:arrC2 withKeyPath:@"arrangedObjects.custId" options:nil]; [table addTableColumn:column]; then i see values of first column (which was second in the first example) and again "(" in the second column. i don't understand that behaviour. how can i bound two array controllers to one table?

    Read the article

  • How can I sort an NSTableColumn of NSStrings ignoring "The " and "A "?

    - by David Barry
    I've got a simple Core Data application that I'm working on to display my movie collection. I'm using an NSTableView, with it's columns bound to attributes of my Core Data store through an NSArrayController object. At this point the columns sort fine(for numeric values) when the column headers are clicked on. The issue I'm having is with the String sorting, they sort, however it's done in standard string fashion, with Uppercase letters preceding lowercase(i.e. Z before a). In addition to getting the case sorting to work properly, I would like to be able to ignore a prefix of "The " or "A " when sorting the strings. What is the best way to go about this in Objective-C/Cocoa?

    Read the article

  • Can't get NSTableView to display data.

    - by Alberto
    Hi! I see there are a lot of questions about this, but nothing helped me to get this work. I have a nib with a NSTableView with three columns (with the right identifiers set) and a class named ShortcutsTableController. In the nib I have a NSObject with class value ShortcutsTableController. I also connected the NSTableView to my controller as I usually do. This is header ShortcutsTableController.h. #import <Cocoa/Cocoa.h> @interface ShortcutsTableController : NSObject <NSTableViewDataSource> { IBOutlet NSTableView *shortcutsTable; NSMutableArray *shortcutsList; } - (int) numberOfRowsInTableView: (NSTableView*) tableView; - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row; @property (assign) IBOutlet NSTableView *shortcutsTable; - (void)setUpTable; @end And this is the implementation file ShortcutsTableController.m. #import "ShortcutsTableController.h" @implementation ShortcutsTableController @synthesize shortcutsTable; - (void)setUpTable { shortcutsList = [[NSMutableArray alloc] init]; NSDictionary *dict1 = [NSDictionary dictionaryWithObjectsAndKeys: @"blabla", @"nameColumn", @"Bla bla bla", @"shortcutColumn", @"Ribla", @"actionColumn", nil]; [shortcutsList addObject:dict1]; [shortcutsTable setDataSource:self]; [shortcutsTable reloadData]; } -(int) numberOfRowsInTableView: (NSTableView *) tableView { return [shortcutsList count]; } - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row { if (row != -1) return [[shortcutsList objectAtIndex:row] objectForKey:[tableColumn identifier]]; return nil; } @end But when i try to build nothing appears in the NSTableView. No errors, no warnings. Note that I call setUpTable from within the Delegate Class Method awakeFromNib. Is there something I am doing wrong? Thank you for you help. —Albé UPDATE. Added lines @property (assign) IBOutlet NSTableView *shortcutsTable; in header and @synthesize shortcutsTable; in implementation. Nothing changes. :(

    Read the article

  • get current selected button cell placed inside tableview using cocoa

    - by Swati
    hi i have a NSTableView i have two columns A and B B contains some data A contains custom button the button is added to column A using this: Below code is placed inside awakeFromNib method NSButtonCell *buttonCell = [[[NSButtonCell alloc] init] autorelease]; [buttonCell setBordered:NO]; [buttonCell setImagePosition:NSImageOnly]; [buttonCell setButtonType:NSMomentaryChangeButton]; [buttonCell setImage:[NSImage imageNamed:@"uncheck.png"]]; [buttonCell setSelectable:TRUE]; [buttonCell setTag:100]; [buttonCell setTarget:self]; [buttonCell setAction:@selector(selectButtonsForDeletion:)]; [[myTable tableColumnWithIdentifier:@"EditIdentifier"] setDataCell:buttonCell]; Some code in display cell of nstableview: -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex { if(tableView == myTable) { if([[tableColumn identifier] isEqualToString:@"DataIdentifier"]) { } else if([[tableColumn identifier] isEqualToString:@"EditIdentifier"]) { NSButtonCell *zCell = (NSButtonCell *)cell; [zCell setTag:rowIndex]; [zCell setTitle:@"abc"]; [zCell setTarget:self]; [zCell setAction:@selector(selectButtonsForDeletion:)]; } } } now i want that when i click on the button the image of button cell gets changed as well as i want to do some coding. When button gets clicked then by default the tableView's reference gets passed. How can i get the button cell reference i looked here for similar problem: Cocoa: how to nest a button inside a Table View cell? but i am unable to add button inside column of NSTableView. How i change the image: - (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; { if(tableView == myTable) { if([[tableColumn identifier] isEqualToString:@"EditIdentifier"]) { NSButtonCell *aCell = (NSButtonCell *)[[tableView tableColumnWithIdentifier:@"EditIdentifier"] dataCellForRow:row]; NSInteger index = [[aCell title]intValue]; if([self.selectedIndexesArray count]>0) { if(![self.selectedIndexesArray containsObject:[NSNumber numberWithInt:index]]) { [aCell setImage:[NSImage imageNamed:@"check.png"]]; [self.selectedIndexesArray addObject:[NSNumber numberWithInt:index]]; } else { [aCell setImage:[NSImage imageNamed:@"uncheck.png"]]; [self.selectedIndexesArray removeObjectAtIndex:[selectedIndexesArray indexOfObject:[NSNumber numberWithInt:index]]]; } } else { [aCell setImage:[NSImage imageNamed:@"check.png"]]; [self.selectedIndexesArray addObject:[NSNumber numberWithInt:index]]; } } } } I have debugged the code and found that proper tag and titles are passed but image applies on more than one button cell, this is too very irregular. cant understand how its working!!! Any suggestions what am i doing wrong??

    Read the article

  • How to select one NSCell in an NSTableView?

    - by Paperflyer
    I have a small NSTableView with a checkbox. Whenever the checkbox is not checked, I want one of the adjacent NSCells to be grayed out and inaccessible. However, I can't figure out how to address only one specific cell. -dataCellForRow of NSTableColumn always changes the template cell for the whole table column. How can I access one single cell?

    Read the article

  • how to set setEnabled: for NSButton in an NSTableView

    - by user460366
    Hi All I have an NSTableView which has three columns. The first one is a checkbox and the third one is a button. The button 'is enabled' state depends on whether or not the checkbox is checked. I am setting the table content in the awakeFromNib method and I am implementing the checkbox state in the - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row method. I need to find a way setEnabled: for the NSButton Thanks

    Read the article

  • Retrieving Data in A NSTableView

    - by Heisennberg
    I have a three column Table View populated by two NSMutableDictionaries which share the same keys (ie key | value1 | value2 ) with dict1(key,value1) and dict2(key,value2). I want to manually enter data in the third column and create the key/value objects in dict2. But when I do that, my code picks the wrong key :S Here's the code for the delegate : - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { if ([[aTableColumn identifier] isEqualToString:@"value2"]) { [dict2 setValue:anObject forKey:[[[aTableView tableColumnWithIdentifier:@"key"] dataCellForRow:rowIndex] stringValue ]]; } } Any idea ?

    Read the article

  • I'm trying to build a to-do-list application in Objective C but coming up short.

    - by lampShade
    I'm getting this error: -[NSCFArray insertObject:atIndex:]: attempt to insert nil Here is the .m file: /* IBOutlet NSTextField *textField; IBOutlet NSTabView *tableView; IBOutlet NSButton *button; NSMutableArray *myArray; */ #import "AppController.h" @implementation AppController -(IBAction)addNewItem:(id)sender { myArray = [[NSMutableArray alloc]init]; tableView = [[NSTableView alloc] init]; [tableView setDataSource:self]; [textField stringValue]; NSString *string = [[NSString alloc] init]; string = [textField stringValue]; [myArray addObject:string]; NSLog(@"%d",[myArray count]); NSLog(@"%@",string); } - (int)numberOfRowsInTableView:(NSTableView *)aTableView { return [myArray count]; } - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { //NSString *data = [myArray objectAtIndex:rowIndex]; return [myArray objectAtIndex:rowIndex]; } @end

    Read the article

  • jerky scrolling in NSTableView

    - by Saurabh
    Hello All, I have a NSTableView with around 70 - 80 rows, each row contain a checkbox, title text and a drop down menu to select data. The problem i am facing is that when i scroll the table it does not scroll smooth. When i remove the NSComboBoxCell it works ok. Here is the code i used to add NSComboBoxCell - NSTableColumn* checkColumn = [tblEditData tableColumnWithIdentifier:@"Timer"]; NSCell *aCell = [aTableColumn dataCellForRow:rowIndex]; [aCell setState:3]; NSComboBoxCell *comboBoxCell = [NSComboBoxCell new]; [comboBoxCell addItemWithObjectValue:@"Timer"]; [comboBoxCell addItemWithObjectValue:@"1"]; [comboBoxCell addItemWithObjectValue:@"3"]; [comboBoxCell addItemWithObjectValue:@"6"]; [comboBoxCell addItemWithObjectValue:@"9"]; [comboBoxCell addItemWithObjectValue:@"12"]; [comboBoxCell setStringValue:aDataRow1.timer_val]; [checkColumn setDataCell:comboBoxCell]; return comboBoxCell; Please advice what should i do to remove the jerky scrolling. Thanks

    Read the article

  • Updating a TableView with a WebService and Saving to CoreData

    - by jcady
    I am working on a project where I have a table view that is currently updated via a web request that returns XML. I implemented -(int)numberOfRowsInTableView:(NSTableView*)tv and -(id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn*)tableColumn row:(int)row in my XML parsing class, and have the table updated with the data that is pulled down from the server. I want to save the data that is pulled down using Core Data, so that the table can be saved/loaded. Then later on application start when the web request is made, it will only add data that is not already present. (The XML is sorted by release date, so later I will check to see which release dates are not loaded up from the Core Data store, and only load newer entries.) How would I go about implementing this? I am a very new Cocoa developer, but have gone through the entire Hillegass book. Thanks so much.

    Read the article

  • NSTableView binding problem

    - by Niklas Ottosson
    I have only just started with XCode (v3.2.2) and Interface Builder and have run into a problem. Here is what I have done: I have made a class to be the datasource of a NSTableView: @interface TimeObjectsDS : NSControl { IBOutlet NSTableView * idTableView; NSMutableArray * timeObjects; } @property (assign) NSMutableArray * timeObjects; @property (assign) NSTableView * idTableView; - (id) init; - (void) dealloc; - (void) addTimeObject: (TimeObj *)timeObject; - (int) count; // NSTableViewDataSource Protocol functions - (int)numberOfRowsInTableView:(NSTableView *)tableView; - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row: (int)row; I have then bound my NSTableView in the View to this datasource like so: I have also bound the View NSTableView to the Model idTableView variable in Interface Builder seen above In the init function I add a element to the mutable array. This is displayed correctly in the NSTableView when I run the application. However when I add another element to the array (of same type as in init) and try to call [idTableView reloadData] on the View nothing happens. In fact the Model idTableView is null. When printing the variable with NSLog(@"idTableView: %@", idTableView) I get "idTableView: (null)" Im runing out of ideas how to fix this. Any ideas to what I could do to fix the binding?

    Read the article

  • Implementing A Static NSOutlineView

    - by spamguy
    I'm having a hard time scraping together enough snippets of knowledge to implement an NSOutlineView with a static, never-changing structure defined in an NSArray. This link has been great, but it's not helping me grasp submenus. I'm thinking they're just nested NSArrays, but I have no clear idea. Let's say we have an NSArray inside an NSArray, defined as NSArray *subarray = [[NSArray alloc] initWithObjects:@"2.1", @"2.2", @"2.3", @"2.4", @"2.5", nil]; NSArray *ovStructure = [[NSArray alloc] initWithObjects:@"1", subarray, @"3", nil]; The text is defined in outlineView:objectValueForTableColumn:byItem:. - (id)outlineView:(NSOutlineView *)ov objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)ovItem { if ([[[tableColumn headerCell] stringValue] compare:@"Key"] == NSOrderedSame) { // Return the key for this item. First, get the parent array or dictionary. // If the parent is nil, then that must be root, so we'll get the root // dictionary. id parentObject = [ov parentForItem:ovItem] ? [ov parentForItem:ovItem] : ovStructure; if ([parentObject isKindOfClass:[NSArray class]]) { // Arrays don't have keys (usually), so we have to use a name // based on the index of the object. NSLog([NSString stringWithFormat:@"%@", ovItem]); //return [NSString stringWithFormat:@"Item %d", [parentObject indexOfObject:ovItem]]; return (NSString *) [ovStructure objectAtIndex:[ovStructure indexOfObject:ovItem]]; } } else { // Return the value for the key. If this is a string, just return that. if ([ovItem isKindOfClass:[NSString class]]) { return ovItem; } else if ([ovItem isKindOfClass:[NSDictionary class]]) { return [NSString stringWithFormat:@"%d items", [ovItem count]]; } else if ([ovItem isKindOfClass:[NSArray class]]) { return [NSString stringWithFormat:@"%d items", [ovItem count]]; } } return nil; } The result is '1', '(' (expandable), and '3'. NSLog shows the array starting with '(', hence the second item. Expanding it causes a crash due to going 'beyond bounds.' I tried using parentForItem: but couldn't figure out what to compare the result to. What am I missing?

    Read the article

  • NSTableView is not showing my data. Why is that happening?

    - by lampShade
    I'm making a "simple" to-do-list project and running into a few bumps in the road. The problem is that my NSTableView is NOT showing the data from the NSMutableArray "myArray" and I don't know why that is. Can someone point out my mistake? /* IBOutlet NSTextField *textField; IBOutlet NSTabView *tableView; IBOutlet NSButton *button; NSMutableArray *myArray; */ #import "AppController.h" @implementation AppController -(IBAction)addNewItem:(id)sender { NSString *myString = [textField stringValue]; NSLog(@"my stirng is %@",myString); myArray = [[NSMutableArray alloc] initWithCapacity:100]; [myArray addObject:myString]; } - (int)numberOfRowsInTableView:(NSTableView *)aTableView { return [myArray count]; } - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { return [myArray objectAtIndex:rowIndex]; } -(id)init { [super init]; [tableView setDataSource:self]; [tableView setDelegate:self]; NSLog(@"init"); return self; } @end

    Read the article

  • How do I edit a row in NSTableView to allow deleting the data in that row and replacing with new d

    - by lampShade
    I'm building a to-do-list application and I want to be able to edit the entries in the table and replace them with new entries. I'm close to being able to do what I want but not quit. Here is my code so far: /* IBOutlet NSTextField *textField; IBOutlet NSTabView *tableView; IBOutlet NSButton *button; NSMutableArray *myArray; */ #import "AppController.h" @implementation AppController -(IBAction)addNewItem:(id)sender { [myArray addObject:[textField stringValue]]; [tableView reloadData]; } - (int)numberOfRowsInTableView:(NSTableView *)aTableView { return [myArray count]; } - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { return [myArray objectAtIndex:rowIndex]; } - (id)init { [super init]; myArray = [[NSMutableArray alloc] init]; return self; } -(IBAction)removeItem:(id)sender { NSLog(@"This is the index of the selected row: %d",[tableView selectedRow]); NSLog(@"the clicked row is %d",[tableView clickedRow]); [myArray replaceObjectAtIndex:[tableView selectedRow] withObject:[textField stringValue]]; [myArray addObject:[textField stringValue]]; //[tableView reloadData]; } @end

    Read the article

  • [Cocoa] Binding CoreData Managed Object to NSTextFieldCell subclass

    - by ndg
    I have an NSTableView which has its first column set to contain a custom NSTextFieldCell. My custom NSTextFieldCell needs to allow the user to edit a "desc" property within my Managed Object but to also display an "info" string that it contains (which is not editable). To achieve this, I followed this tutorial. In a nutshell, the tutorial suggests editing your Managed Objects generated subclass to create and pass a dictionary of its contents to your NSTableColumn via bindings. This works well for read-only NSCell implementations, but I'm looking to subclass NSTextFieldCell to allow the user to edit the "desc" property of my Managed Object. To do this, I followed one of the articles comments, which suggests subclassing NSFormatter to explicitly state which Managed Object property you would like the NSTextFieldCell to edit. Here's the suggested implementation: @implementation TRTableDescFormatter - (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string errorDescription:(NSString **)error { if (anObject != nil){ *anObject = [NSDictionary dictionaryWithObject:string forKey:@"desc"]; return YES; } return NO; } - (NSString *)stringForObjectValue:(id)anObject { if (![anObject isKindOfClass:[NSDictionary class]]) return nil; return [anObject valueForKey:@"desc"]; } - (NSAttributedString*)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attrs { if (![anObject isKindOfClass:[NSDictionary class]]) return nil; NSAttributedString *anAttributedString = [[NSAttributedString alloc] initWithString: [anObject valueForKey:@"desc"]]; return anAttributedString; } @end I assign the NSFormatter subclass to my cell in my NSTextFieldCell subclass, like so: - (void)awakeFromNib { TRTableDescFormatter *formatter = [[[TRTableDescFormatter alloc] init] autorelease]; [self setFormatter:formatter]; } This seems to work, but is extremely patch. On occasion, clicking to edit a row will cause its value to nullify. On other occasions, the value you enter on one row will populate other rows within the table. I've been doing a lot of reading on this subject and would really like to get to the bottom of this. What's more frustrating is that my NSTextFieldCell is rendering exactly how I would like it to. This editing issue is my last obstacle! If anyone can help, that would be greatly appreciated.

    Read the article

  • How do I update a NSTableView when its data source has changed?

    - by Jergason
    I am working along with Cocoa Programming For Mac OS X (a great book). One of the exercises the book gives is to build a simple to-do program. The UI has a table view, a text field to type in a new item and an "Add" button to add the new item to the table. On the back end I have a controller that is the data source and delegate for my NSTableView. The controller also implements an IBAction method called by the "Add" button. It contains a NSMutableArray to hold the to do list items. When the button is clicked, the action method fires correctly and the new string gets added to the mutable array. However, my data source methods are not being called correctly. Here they be: - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView { NSLog(@"Calling numberOfRowsInTableView: %d", [todoList count]); return [todoList count]; } - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { NSLog(@"Returning %@ to be displayed", [todoList objectAtIndex:rowIndex]); return [todoList objectAtIndex:rowIndex]; } Here is the rub. -numberOfRowsInTableView only gets called when the app first starts, not every time I add something new to the array. -objectValueForTableColumn never gets called at all. I assume this is because Cocoa is smart enough to not call this method when there is nothing to draw. Is there some method I need to call to let the table view know that its data source has changed, and it should redraw itself?

    Read the article

  • NSTableView don't display data

    - by Tomas Svoboda
    HI, I have data in NSMutableArray and I want to display it in NSTableView, but only the number of cols has changed. This use of NSTableView is based on tutorial: http://www.youtube.com/watch?v=5teN5pMf-rs FinalImageBrowser is IBOutlet to NSTableView @implementation AppController NSMutableArray *listData; - (void)awakeFromNib { [FinalImageBrowser setDataSource:self]; } - (IBAction)StartReconstruction:(id)sender { NSMutableArray *ArrayOfFinals = [[NSMutableArray alloc] init]; //Array of list with final images NSString *FinalPicture; NSString *PicNum; int FromLine = [TextFieldFrom intValue]; //read number of start line int ToLine = [TextFieldTo intValue]; //read number of finish line int RecLine; for (RecLine = FromLine; RecLine < ToLine; RecLine++) //reconstruct from line to line { Start(RecLine); //start reconstruction //Create path of final image FinalPicture = @"FIN/final"; PicNum = [NSString stringWithFormat: @"%d", RecLine]; FinalPicture = [FinalPicture stringByAppendingString:PicNum]; FinalPicture = [FinalPicture stringByAppendingString:@".bmp"]; [ArrayOfFinals addObject:FinalPicture]; // add path to array } listData = [[NSMutableArray alloc] init]; [listData autorelease]; [listData addObjectsFromArray:ArrayOfFinals]; [FinalImageBrowser reloadData]; NSBeep(); //make some noise NSImage *fin = [[NSImage alloc] initWithContentsOfFile:FinalPicture]; [FinalImage setImage:fin]; } - (int)numberOfRowsInTableView:(NSTableView *)tv { return [listData count]; } - (id)tableView:(NSTableView *)tv objectValueFromTableColumn:(NSTableColumn *)tableColumn row:(int)row { return (NSString *)[listData objectAtIndex:row]; } @end when the StartReconstruction end the number of cols have changed right, but they're empty. When I debug app, items in listData is rigth. Thanks

    Read the article

  • Binding CoreData Managed Object to NSTextFieldCell subclass

    - by ndg
    I have an NSTableView which has its first column set to contain a custom NSTextFieldCell. My custom NSTextFieldCell needs to allow the user to edit a "desc" property within my Managed Object but to also display an "info" string that it contains (which is not editable). To achieve this, I followed this tutorial. In a nutshell, the tutorial suggests editing your Managed Objects generated subclass to create and pass a dictionary of its contents to your NSTableColumn via bindings. This works well for read-only NSCell implementations, but I'm looking to subclass NSTextFieldCell to allow the user to edit the "desc" property of my Managed Object. To do this, I followed one of the articles comments, which suggests subclassing NSFormatter to explicitly state which Managed Object property you would like the NSTextFieldCell to edit. Here's the suggested implementation: @implementation TRTableDescFormatter - (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string errorDescription:(NSString **)error { if (anObject != nil){ *anObject = [NSDictionary dictionaryWithObject:string forKey:@"desc"]; return YES; } return NO; } - (NSString *)stringForObjectValue:(id)anObject { if (![anObject isKindOfClass:[NSDictionary class]]) return nil; return [anObject valueForKey:@"desc"]; } - (NSAttributedString*)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attrs { if (![anObject isKindOfClass:[NSDictionary class]]) return nil; NSAttributedString *anAttributedString = [[NSAttributedString alloc] initWithString: [anObject valueForKey:@"desc"]]; return anAttributedString; } @end I assign the NSFormatter subclass to my cell in my NSTextFieldCell subclass, like so: - (void)awakeFromNib { TRTableDescFormatter *formatter = [[[TRTableDescFormatter alloc] init] autorelease]; [self setFormatter:formatter]; } This seems to work, but falls down when editing multiple rows. The behaviour I'm seeing is that editing a row will work as expected until you try to edit another row. Upon editing another row, all previously edited rows will have their "desc" value set to the value of the currently selected row. I've been doing a lot of reading on this subject and would really like to get to the bottom of this. What's more frustrating is that my NSTextFieldCell is rendering exactly how I would like it to. This editing issue is my last obstacle! If anyone can help, that would be greatly appreciated.

    Read the article

  • Working through exercises in "Cocoa Programming for Mac OS X" - I'm stumped

    - by Zigrivers
    I've been working through the exercises in a book recommended here on stackoverflow, however I've run into a problem and after three days of banging my head on the wall, I think I need some help. I'm working through the "Speakline" exercise where we add a TableView to the interface and the table will display the "voices" that you can choose for the text to speech aspect of the program. I am having two problems that I can't seem to get to the bottom of: I get the following error: * Illegal NSTableView data source (). Must implement numberOfRowsInTableView: and tableView:objectValueForTableColumn:row: The tableView that is supposed to display the voices comes up blank I have a feeling that both of these problems are related. I'm including my interface code here: #import <Cocoa/Cocoa.h> @interface AppController : NSObject <NSSpeechSynthesizerDelegate, NSTableViewDelegate> { IBOutlet NSTextField *textField; NSSpeechSynthesizer *speechSynth; IBOutlet NSButton *stopButton; IBOutlet NSButton *startButton; IBOutlet NSTableView *tableView; NSArray *voiceList; } - (IBAction)sayIt:(id)sender; - (IBAction)stopIt:(id)sender; @end And my implementation code here: #import "AppController.h" @implementation AppController - (id)init { [super init]; //Log to help me understand what is happening NSLog(@"init"); speechSynth = [[NSSpeechSynthesizer alloc] initWithVoice:nil]; [speechSynth setDelegate:self]; voiceList = [[NSSpeechSynthesizer availableVoices] retain]; return self; } - (IBAction)sayIt:(id)sender { NSString *string = [[textField stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; //Is the string zero-length? if([string length] == 0) { NSLog(@"String from %@ is a string with a length of %d.", textField, [string length]); [speechSynth startSpeakingString:@"Please enter a phrase first."]; } [speechSynth startSpeakingString:string]; NSLog(@"Started to say: %@", string); [stopButton setEnabled:YES]; [startButton setEnabled:NO]; } - (IBAction)stopIt:(id)sender { NSLog(@"Stopping..."); [speechSynth stopSpeaking]; } - (void) speechSynthesizer:(NSSpeechSynthesizer *)sender didFinishSpeaking:(BOOL)complete { NSLog(@"Complete = %d", complete); [stopButton setEnabled:NO]; [startButton setEnabled:YES]; } - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView { return [voiceList count]; } - (id)tableView: (NSTableView *)tv objecValueForTableColumn: (NSTableColumn *)tableColumn row:(NSInteger)row { NSString *v = [voiceList objectAtIndex:row]; NSLog(@"v = %@",v); NSDictionary *dict = [NSSpeechSynthesizer attributesForVoice:v]; return [dict objectForKey:NSVoiceName]; } /* - (BOOL)respondsToSelector:(SEL)aSelector { NSString *methodName = NSStringFromSelector(aSelector); NSLog(@"respondsToSelector: %@", methodName); return [super respondsToSelector:aSelector]; } */ @end Hopefully, you guys can see something obvious that I've missed. Thank you!

    Read the article

1 2  | Next Page >