Hi - I'm having an issue when in Edit Mode with a column created dynamically. If I scroll the grid row out of view while it's in Edit Mode I'll get an exception. This is only when it is required to create my columns dynamically.
I've attached a link to a sample project to illustrate this issue. By Double Clicking the first cell, then scrolling down in the grid will cause an exception to an undefined key. I'm wondering how do I resolve this issue.
Many thanks in advance. I'll be sure to remove the sample project.
Hi,
To be honest, i'm not sure how to get proper focus to the UITextField within your Accessory view. I spent a bit of time trying to get it to work, but to no avail.
I did set it up so that editor does properly update the cell though.
public override void CellEnteringEditMode (IGGridViewDataSourceHelper dsh, IGGridViewCell cell, NSObject val, UIView editor, IGGridViewColumnDefinition col) { accessory = new Accessory((UITextField)editor); ((UITextField)editor).InputAccessoryView = accessory.View; this.PerformSelector (new MonoTouch.ObjCRuntime.Selector ("setFocus"), null, .1); accessory.TextField.EditingDidEnd += (object sender, EventArgs e) => { this.EndEditing((UITextField)sender, dsh, cell, col); }; accessory.TextField.ShouldReturn += (textField) => { this.EndEditing(textField, dsh, cell, col); return true; }; } private void EndEditing(UITextField textField, IGGridViewDataSourceHelper dsh, IGGridViewCell cell, IGGridViewColumnDefinition col) { dsh.EndEditing(); cSimpleGrid dataRow = (cSimpleGrid)dsh.ResolveDataObjectForRow (cell.Path); dataRow [col.FieldKey] = cell.TextLabel.Text = textField.Text; textField.ResignFirstResponder(); } [Export("setFocus")] public void SetFocus() { accessory.TextField.BecomeFirstResponder (); }
}
-SteveZ
Thanks Zaharuk so much for that. I saw this code in another one of your posts in the past. I actually tried using that for another issue I was experiencing but not this one. It worked perfectly. Thanks.
I do have one last implementation that I'm working on that is really giving me fits. I'm hoping you can assist and I'll be able to leave you alone. I've tried almost everything I can think of but it's just not perfect.
My goal is because sometimes the editing cell width will be minimal due to lack of screen size, I'm looking to implement the same functionality that the Numbers (excel for iPad) App has. What it does is when the cell enters the edit mode an Input Accessory appears with a TextField in the Accessory bar, allowing you ample space to type into the Accessory TextField and it returns to the cell being edited. It also has a custom keyboard which I'm also implementing allowing the user to input some quick data strings and such. I understand how to get the accessory and inputView to appear but I can't get the Text Field in the Accessory to be proper first responder (if that even correct) and properly wire the Editing Cell, to the Text Field in the Accessory View to the Custom Keyboard. I want them all wired together so that whatever is typed in the TextField in the Accessory or pressed in the custom keyboard all reflects back into the cell.
I've provided another link with sample project that begins to wire this up, but just doesn't work as intended yet. I'm wondering if you would have a good approach to wiring these all up.
Thanks so much.
So, i thought i had exposed a method that would easily allow you to just override it and apply the value to your cell. Apparently i didn't :(
I'll definitely add that though.
Fortunately, the logic you'd have to reimplement is trivial. Jus add this method to your column and you should be good to go:
public override void RemoveEditor (IGGridView gridView, IGCellPath path, IGGridViewDataSourceHelper dataSource, bool cellVisible, bool anotherCellEnteringEditMode) { gridView.UnregisterKeyboard (!anotherCellEnteringEditMode); IGGridViewCell cell = (IGGridViewCell)gridView.ResolveCellForPath (path); UITextField field = (UITextField)cell.Subviews [0]; cSimpleGrid dataRow = (cSimpleGrid)dataSource.ResolveDataObjectForRow (path); dataRow [_fieldKey] = cell.TextLabel.Text = field.Text; float duration = cellVisible? dataSource.EditingTransitionDuration : 0.0f; UIView.Transition (field, cell.TextLabel, duration, UIViewAnimationOptions.TransitionFlipFromTop, null); }
Thanks I got the sample. And will take a look now.
Can you please remove the download link.
In the future, if you delete the bin and obj folders before zipping up your project, it'll be a lot smaller, and you won't be distributing our controls.
Thanks,