Can't programmatically bind NSImageView in view-based NSTablveView cellView - nstableview

I have a view-based NSTableView which is a single column with a custom CellView containing about a dozen text fields and a single NSImageView.
-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
ComboTableCellView* view = [tableView makeViewWithIdentifier:[tableColumn identifier] owner:nil];
// I bind the text fields with:
[[view nameView] bind:NSValueBinding toObject:view withKeyPath:#"objectValue.name" options:nil];
// I bind the NSImageView with:
NSMutableDictionary* statusOptions = [[[NSMutableDictionary alloc] initWithCapacity:0] autorelease];
[options setObject:kStatusIconTransformerName forKey:NSValueTransformerNameBindingOption];
[[view statusView] bind:NSValueBinding toObject:view withKeyPath:#"objectValue.status" options:statusOptions];
return (view);
}
My transformer takes "status" which is an NSNumber and returns an NSImage because status will be a number from 1 to 4. This works in a cell based NSTableView with an NSImage column.
However, in my view-based NSTableView I get:
Cannot remove an observer (NSAutounbinderObservance 0x600000028ac0) for the key path "objectValue.status" from (ComboTableCellView 0x6180001e3e00), most likely because the value for the key "objectValue" has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the ComboTableCellView class.
How can I correctly bind an NSImageView that is within a reuseable view used as the row/cellview in a view-based NStableView?

Related

NSTableView with images

I have NSTableView with 3 tabs.
Now, I want an image inside every tab, how can i do ?
I must use NSImage with position, so ?
NSImage *theImage;
theImage = [NSImage imageNamed#"myImage.png"];
you can do like this:
in code create one NSMutableArray with property and synthesize
header file:
#property (readwrite, retain) NSMutableArray *imageArray
implementation file:
#synthesize imageArray
do like this wherever you want to add image to array:
NSMutableDictionary *imageDict = [NSMutableDictionary dictionary];
[imageDict setObject:[NSImage imageNamed:#"ABC"] forKey:#"image1"];
[imageDict setObject:[NSImage imageNamed:#"XYZ"] forKey:#"image2"];
[imageDict setObject:[NSImage imageNamed:#"XYZ"] forKey:#"image3"];
[imageArray imageDict];
[self setImageArray:imageArray];
take array controller in XIb, bind arraycontroller to imageArray array, bind table column with the array controller with given key path (here keypath is image1,image2 and image3).
one More thing take image name without extension . drag and drop image cell on tableview cell

NSTableView set column to disabled

I have a NSTableView tied to a NSArrayController. The first column are checkboxes. I want to have the users select the rows to perform an action on via the checkboxes and when the user clicks the "Run" button I want to set the state of that column to be un-editable.
How do I go about this?
Thanks!
rather than disabling the column I disable the individual checkbox cells in my app based on a global app state.
Preconditions:
1.) your "Run button" sets some sort of a global state in your controller class. For me its a "Play" button that sets a member in my controller like:
if ([self gotoNextSong])
_currentPlayMode = PLAYMODE_PLAY;
else
_currentPlayMode = PLAYMODE_STOP;
2.) Your controller is already a delegate to the NSTableView. If not:
In your MyController.h:
#interface MyController : NSObject <NSTableViewDelegate>
In your MyController.m make your controller to a delegate of the table - e.g. in your init: method
[self.myTableView setDelegate:self];
3.) You know the identifier of the column that holds the checkboxes. If not, either its the automatic name like column1, column2, ... or you can set it in Interface Builder while the column is active in Identity Inspector / Identity / Identifier. In my case the column name is "checkboxes"
Solution:
1.) Add a delegate method for the table to inform you when the cells are rendered. Inside this method enable or disable the cells of the checkbox-row as desired
- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn: (NSTableColumn *)aTableColumn row:(int)rowIndex
{
if(([[aTableColumn identifier] isEqualToString:#"checkboxes"]))
{
if (_currentPlayMode == PLAYMODE_PLAY)
[aCell setEnabled:NO];
else
[aCell setEnabled:YES];
}
}
2.) Make sure that your RUN-button not only sets the global state (in my case _currentPlayMode), but also force the NSTableView to redraw afterwards:
[self.myTableView setNeedsDisplay:YES];

Flex 3: dynamically created checkbox column in datagrid - data population issues and event listener

I have a datagrid control in my mxml file:
Now in my AS file, in the result function when obtaining data from DB, I can create columns dynamically. Let's say I create 1 column (client name):
private function GetDebtors_Result(event:ResultEvent):void
{
var arrayCol:Array = new Array();
var xmlSrc:XML = new XML("<main></main>");
var xmlTmp:XML;
var colClientname:DataGridColumn;
//Build an XML from DB data received (could as well use "event.result" directly to act as dataprovider for the datagrid, but I needed to break it down here)
for each(var o:Object in event.result)
{
xmlTmp = <row>
<CLIENTNAME>{o.CLIENTNAME}</CLIENTNAME>
</row>;
xmlSrc.appendChild(xmlTmp);
}
//Create the column CLIENTNAME
colClientname = new DataGridColumn("CLIENTNAME");
colClientname.headerText = "Client Name";
//Add the newly created column in the "Column" array.
arrayCol.push(colClientname);
//Use the "Column" array to set the columns of the datagrid.
dgSearch.columns = arrayCol;
//Populate the datagrid with the XML data.
dgSearch.dataProvider = xmlSrc.row;
}
This works well.
Now comes the issue: I need to add a second column which will contain checkboxes. They will be selected or deselected depending on the data from database. I'll show how I've done it by updating the same "GetDebtors_Result" function as above (added lines are commented as "// ADDED"):
private function GetDebtors_Result(event:ResultEvent):void
{
var arrayCol:Array = new Array();
var xmlSrc:XML = new XML("<main></main>");
var xmlTmp:XML;
var colClientname:DataGridColumn;
var colSel:DataGridColumn; // **ADDED**
//Build an XML from DB data received (could as well use "event.result" directly to act as dataprovider for the datagrid, but I needed to break it down here)
for each(var o:Object in event.result)
{
xmlTmp = <row>
<CLIENTNAME>{o.CLIENTNAME}</CLIENTNAME>
<SELECTED>{(o.SELECTED == 1)?true:false}</SELECTED> //**ADDED**
</row>;
xmlSrc.appendChild(xmlTmp);
}
//Create the column CLIENTNAME
colClientname = new DataGridColumn("CLIENTNAME");
colClientname.headerText = "Client Name";
//Create the column SELECTED
colSel = new DataGridColumn("SELECTED"); // **ADDED**
colSel.headerText = ""; // **ADDED**
colSel.itemRenderer = new ClassFactory(mx.controls.CheckBox); // **ADDED**
colSel.dataField = "SELECTED"; // **ADDED**
//Add the newly created column in the "Column" array.
arrayCol.push(colClientname);
//Add the "selection" column in the "Column" array.
arrayCol.push(colSel); // **ADDED**
//Use the "Column" array to set the columns of the datagrid.
dgSearch.columns = arrayCol;
//Populate the datagrid with the XML data.
dgSearch.dataProvider = xmlSrc.row;
}
Problem #1: The checkbox column appears, I can check and uncheck the checkboxes, but they are not checked/unchecked respective to DB data when loaded.
Problem #2: How do I associate a function to the checkboxes, for instance one which will update the XML so that I can save the new data to the DB?
Anybody got the solution? Thank you in advance.
Seems to be a very old question that I saw today.
Hopefully you would have found out the solution by now, just in-case if anyone has same problem:
While adding a checkbox to column- just instantiate it 1st:
var chkTempCheck: Checkbox = new CheckBox();
Then set all the properties required:
chkTempCheck.selected = o.dBColumnToDecideCheckUnCheck
here 'o' is the Object you are using from event.result.
This will work for sure!
The initial scenario was: all columns were defined in the mxml file. The checkbox column used itemrenderer and was working properly. I was using the same datagrid in 3 different cases - only thing was that some columns were set visible/invisible depending on the 'views'. The problem was when shifting 'views' and populate the grid and shift 'views' again, the column widths kept increasing exponentially. I excluded the checkbox column and everything worked fine; columns widths were ok. I included the checkbox column back and tried setting the column widths in AS file and the column-increasing-exponentially problem was fixed but the column widths were never the same when populating grid in view A and when populating grid in view B. ...So I ventured out in trying to set the columns in AS file just after obtaining DB data. Hope you can find yourself in those situations. Thanks for helping.

UITextField not setting NSString

I have a pickerView in a popOver.
When the user selects a row from the pickerView, it should be stored into a UITextField (subject)
The method i'm having troubles is:
- (void) viewWithPickerController:(ViewWithPickerController*) viewWithPickerController didSelectValue:(NSString*) value
{ NSLog(#"selected value is: %#",value);
subject.text = [NSString stringWithFormat:#"%#",value];
NSLog(#"subject is: %#",subject.text);
}
Where value is the row of the pickerView: it logs the right value but it doesn't set it to the textField subject, which seems to be null.
Where am i wrong?
You need to make sure your "subject" IBOutlet is set.
If you're doing this picker view method before your XIB / view controller is instantiated, that would explain why subject is a nil object.
How else would you be instantiating "subject"?

Please explain me how to control a Table View in Cocoa?

I search Google to find a good answer but the most tutorials are shown in previous Xcode Versions...
Also, I don't want to drag-n-drop cells from the Interface Builder, but to control the Table View programmatically (from an NSObject subclass file).
What I currently do is this: 1. Create a file named tableController.h that is a subclass of NSObject.
2. I create an NSObject Object in my Nib File (and set it as a subclass of tableController).
3. I drag a Table View to my window.
4. I CTRL+Drag from the Table View to my tableController.h so to create the outlet "tableView"
5. I create these functions in the interface file:
-(int)numberOfRowsInTableView:(NSTableView *)cocoaTV;
-(id)tableView:(NSTableView *)cocoaTV:objectValueForTableCollumn:(NSTableColumn *)tableCollumn row:(int)row;
6. I implement the functions like this:
-(int)numberOfRowsInTableView:(NSTableView *)cocoaTV{
return 5;
}
-(id)tableView:(NSTableView *)cocoaTV:objectValueForTableCollumn:(NSTableColumn *)tableCollumn row:(int)row{
NSArray *tvArray = [[NSArray alloc]initWithObjects:#"1",#"2",#"3",#"4",#"5", nil];
NSString *v = [tvArray objectAtIndex:row];
return v;
}
Then I CTRL+Drag from the Object in the Interface Builder to the Table View to set the dataSource and to set it as delegate.
When I build and Run the App it shows that it has created the 5 Rows but in every cell in every column it says "Table View Cell".
Any help would be appreciated....
-(id)tableView:(NSTableView *)cocoaTV:objectValueForTableCollumn:(NSTableColumn *)tableCollumn row:(int)row is wrong.. i'm not sure how it compiles, to be honest (unless there was an error copy/pasting it). the method should look like:
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSArray *tvArray = [[NSArray alloc]initWithObjects:#"1",#"2",#"3",#"4",#"5", nil];
NSString *v = [tvArray objectAtIndex:row];
return v;
}

Resources