Mac Objective C NSTableView and NSTextViewCell, know when user edits cell is done - nstableview

Not sure why this is elusive, have looked at the docs. How to know when the user edits a NSTableViewCell in an NSTableView?
Have setup the Text Filed Cell in IB Action to Sent On End Editing and hooked up the sent action, but no joy.... it does not get called when user is done editing a cell.

#pragma mark - Text Table Delegates
- (BOOL) control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
{
self.editingString = [[NSString alloc] initWithString:fieldEditor.string];
[self performSelector:#selector(updateSelection) withObject:nil afterDelay:0.1];
return YES;
}

Related

How to Stop Single Tap From firing before Double Tap

I am trying to set a simple double tap recognition before moving to more complicated interactions. I have the single and double tap being recognised. However, my problem is that the double tap doesn't fire without the single tap.
I have seen the code which covers introducing a requirement to fail, but the sample code I do not understand how to modify to make work with my standard approach.
Here is my code - at the moment I am just trying to get the log to fire and it is. But on double tap I get the single tap message which I don't want. I have tried changing the TapGestureRecognizer event settings to no avail.
- (IBAction)didTapPhoto1:(UITapGestureRecognizer *)sender; {
NSLog(#"Did Tap Photo1 !");
}
- (IBAction)didDoubleTapPhoto1:(UITapGestureRecognizer *)sender; {
NSLog(#"DoubleTap");
}
Thank you
Use UIGestureRecognizer requireGestureRecognizerToFail: method.
[singleTapGestureRecognizer requireGestureRecognizerToFail:doubleTapGestureRecognizer].
There is a side effect of this method, if you only tap one time on the screen, it will react slower than that without calling the method.
Edit: It seems that you create the gesture recognizer in Storyboard or xib. You can also do it with code.
UITapGestureRecognizer *singleGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(didTapPhoto1:)] ;
singleGR.numberOfTapsRequired = 1 ;
UITapGestureRecognizer *doubleGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(didDoubleTapPhoto1:)] ;
doubleGR.numberOfTapsRequired = 2 ;
// you can change self.view to any view in the hierarchy.
[self.view addGestureRecognizer:singleGR] ;
[self.view addGestureRecognizer:doubleGR] ;
[singleGR requireGestureRecognizerToFail:doubleGR] ;

Blackberry 10 SystemPrompt->inputField does not change value on user input

I need to display system input dialog: title, some text, input field, OK & Cancel buttons.
I'm new to BB development, so I carefully read docs and samples: http://developer.blackberry.com/native/documentation/cascades/ui/dialogs_toasts/prompts.html
and write the same code (let's say doc author cheated a bit in the most important part - not covering obtaining of user input with non-compiling source code - "qDebug() << "Prompt Accepted:" << text;").
void MainPage::showPrompt() {
SystemPrompt *dialog = new SystemPrompt();
dialog->inputField()->setDefaultText("TEST");
QObject::connect(dialog, SIGNAL(finished(bb::system::SystemUiResult::Type)),
this, SLOT(promptHandler(bb::system::SystemUiResult::Type)));
dialog->show();
}
void MainPage::promptHandler(bb::system::SystemUiResult::Type value) {
if (value == SystemUiResult::ConfirmButtonSelection) {
SystemPrompt *dialog = (SystemPrompt *)QObject::sender();
qDebug("text is: '%s'", qPrintable(dialog->inputField()->defaultText()));
}
}
Regardless of user input on device/simulator, inputField()->defaultText() value is always "TEST" as it was initialized.
How do I get the user input here? dialog->exec() does not change anything.
PS. Expert level question: And how do I allow empty input in SystemPrompt dialog (by default "OK" button becomes disabled on empty input).
Shame upon me. I did not read documentation carefully.
->inputFieldTextEntry() does contain the user input.
PS. First time I see such sophisticated logic of handling such simple thing as user input in text edit...

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;
}

Custom Table View Cells with TextField Problems

HI, So here's what I'm trying to do. I have a table View and I'm using Custom Table View Cells with text Fields. Basically you enter Text in the fields and it saves it to a managed object context. I have set up the Table View thusly;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//static NSString *CustCell=#"CustomCell";
static NSString *CellIdentifier = #"Cell";
CustomCell *cell = (CustomCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell== nil) {
cell= [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
switch (indexPath.row) {
case 0:
cell.primaryLabel.text = #"Name";
cell.mainTextField.text=product.prodName;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
break;
case 1:
cell.primaryLabel.text = #"Store";
cell.mainTextField.text=product.store;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
break;
case 2:
cell.primaryLabel.text=#"Amount";
cell.mainTextField.text=product.amount;
cell.mainTextField.keyboardType=UIKeyboardTypeNumberPad;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
break;
case 3:
cell.primaryLabel.text=#"Measure";
cell.detailLabel.text=product.measure;
cell.mainTextField.hidden=YES;
break;
case 4:
cell.primaryLabel.text=#"Package";
cell.detailLabel.text=product.container;
cell.mainTextField.hidden=YES;
break;
case 5:
cell.primaryLabel.text=#"Aisle";
cell.detailLabel.text=product.aisle;
cell.mainTextField.hidden=YES;
break;
case 6:
cell.primaryLabel.text=#"Note";
cell.mainTextField.text=product.note;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
break;
default:
break;
}
return cell;
}
So here's my issue. At runtime I can enter text in cells 1-3 no problem it saves and everything's happy. But if I enter anything in cell 6 it returns Null for cell.nameTextField.text and I don't know why.
What I've done.
1. I tried creating a single instance cell in the nib and placing it in that cell.
2. I tried Setting it to index.row 0 of a new section.
3. Tried adding a text field to the content view of a standard cell at that index.
4. commented out the save method for that cell.
5. tried creating a separate textField and setting the cell.mainTextFiled to Hidden.
6. Tried creating the table View Programmatically without using the nib.
7. It all worked when I used single instance cells from the nib for all four of these cells. If that's the answer, so be it. But Custom Table View Cells created programmatically are so much more concise and elegant.
To add insult to insanity If I move that cell to an index of 5 or below everything works great. Any index over 5 and it blows up.
I have scoured the web and the dev docs as well as the 4 iPhone Dev books that I have.
I am here because I have exhausted what I can do. I'm sure it's something dumb that I'm missing but I'm flummoxed. Any help would be appreciated.
The ultimate goal is to have have notes in a second section with more room to write.
Yes I know there are other ways to do this but it seems that this should work and I would love to know why it doesn't.
Oh, I should mention that I have only been using the iPhone simulator. I have not tried running on a phone.
Thanks.
OK, I'm an idiot. After posting this I found the answer (of course!) Simply put. When the cell with the text field scrolls out of view it dequeues the cell. When the cell reappears it gets re-instantiated with a shiny clean text field. So now I'm looking at ways to overcome this. Arrays come to mind. I'll post what I find. If anyone has ideas about this problem I'd love to hear them.

Dynamics Ax: Alert when any record changes

I want to send an alert in Ax, when any field in the vendor table changes (and on create/delete of a record).
In the alert, I would like to include the previous and current value.
But, it appears that you can't set alerts for when any field in a table changes, but need to set one up for EVERY FIELD?! I hope I am mistaken.
And how can I send this notification to a group of people
I have created a new class with a static method that I can easily call from any .update() method to alert me when a record changes, and what changed in the record.
It uses the built in email templates of Ax as well.
static void CompareAndEmail(str emailTemplateName, str nameField, str recipient, Common original, Common modified)
{
UserInfo userInfo;
Map emailParameterMap = new Map(Types::String, Types::String);
str changes;
int i, fieldId;
DictTable dictTable = new DictTable(original.TableId);
DictField dictField;
;
for (i=1; i<=dictTable.fieldCnt(); i++)
{
fieldId = dictTable.fieldCnt2Id(i);
dictField = dictTable.fieldObject(fieldId);
if (dictField.isSystem())
continue;
if (original.(fieldId) != modified.(fieldId))
{
changes += strfmt("%1: %2 -> %3 \n\r",
dictField.name(),
original.(fieldId),
modified.(fieldId)
);
}
}
//Send Notification Email
select Name from UserInfo where userInfo.id == curUserId();
emailParameterMap.insert("modifiedBy", userInfo.Name);
emailParameterMap.insert("tableName", dictTable.name());
emailParameterMap.insert("recordName", original.(dictTable.fieldName2Id(nameField)));
emailParameterMap.insert("recordChanges", changes);
SysEmailTable::sendMail(emailTemplateName, "en-us", recipient, emailParameterMap);
}
Then in the .update() method I just add this one line
//Compare and email differences
RecordChangeNotification::CompareAndEmail(
"RecChange", //Template to use
"Name", //Name field of the record (MUST BE VALID)
"user#domain.com", //Recipient email
this_Orig, //Original record
this //Modified record
);
The only things I want to improve upon are:
moving the template name and recipient into a table, for easier maintenance
better formatting for the change list, I don't know how to template that (see: here)
As you have observed the alert system is not designed for "any" field changes, only specific field changes.
This is a bogus request anyway as it would generate many alarts. The right thing to do is to enable database logging of the VendTable table, then send a daily report (in batch) to those interested.
This is done in Administration\Setup\Database logging. There is a report in Administration\Reports. You will need to know the table number to select the table.
This solution requires a "Database logging" license key.
If you really need this feature, then you can create a class that sends a message/email with the footprint of the old record vs the new record. Then simply add some code in the table method "write"/"update"/"save" to make sure you class is run whenever vendtable gets edited.
But I have to agree with Jan. This will generate a lot of alerts. I'd spend some energy checking if the modifications done in vendtable are according to the business needs, and prohibit illegal modifications. That includes making sure only the right people have enough access.
Good luck!
I do agree with suggestion of Skaue.you just write and class to send the mail of changes in vend table.
and execute this class on update method of vendtable.
thanks and Regards,
Deepak Kumar

Resources