Custom UITableViewCell with UITextField editingDidEnd race condition - delegates

I have UITableViewController with Edit/Save button as BarItem. I have a custom cell which displays UITextField in edit mode. I am able to save modified text when I move focus to another cell etc. no problem. However my problem begins when I attempt to modify a field and press Save button that triggers setEditing:NO save etc. What I believe is happening is a race condition where Save action is triggered before editingDidEnd is processed and as a result I am not saving all of the data.
Any suggestions on how to handle this? Am I to go through all visible cells to save all of the data on save? I can definitely do that, but am I going to get into same problem with scroll and edit button clicked? Is there a better way to flush messaging queue?

Given that I have no takers, I think I am stuck with what I know:
in done/save (i.e. setEditing:NO) handling go through all cells and save their data
Keep updating data every time there is a change i.e. in Value Changed perhaps
attempt using UITextFieldDelegate and textFieldShouldEndEditing but I am not sure this would work since I will probably run into the same problem that I have.
I believe endEditing inside setEditing will solve the problem as it supposed to resign first responders for text fields.

Related

NSTextField edit coalescing

I am writing a Cocoa app which contains several NSTextFields. I am trying to propagate changes to the text in the text field to my model layer, but since I am registering an Undo action when the model is updated, this makes it a bit more complicated than simply listening for controlTextDidChange:.
If I hook onto the delegate method controlTextDidChange:, then it gets called once for every key pressed. If I update the model then, the model will treat each separate keypress as a separate Undo event. This is not desirable. What I want is to be notified when the default "Undo Typing" action is registered with the Undo manager, so I can update the model then. The NSTextField registers one (and only one) such event, when I pause typing for a moment. Unfortunately, I have no idea when this occurs.
I have tried listening for controlTextDidEndEditing:, and updating the model in that delegate method, but then I have to explicitly tab out of the text field before the model will update. Since I archive my model object directly in my NSDocument subclass, doing this will result in data loss for the user if they save the document after changing the contents of the text field, but don't tab out of the text field first, because the model would not have been updated in time. Therefore, this technique will not work.
I have also tried hooking onto the text field's field editor (during control:textShouldBeginEditing:) and listening for textDidEndEditing:, but then I find that this simply doesn't fire, so the model won't be updated, causing data loss as described in the previous paragraph. Can anyone help me figure this out? Thanks!
By default, Apple NSTextField leaves dangling edits as you mentioned.
Because of this problem, amongst others, I subclassed NSTextField and NSApplication to handle text field editing the way it should be handled: Pressing 'Enter', clicking outside the field, and other actions should end editing and produce the Undo entry.
Also, I highly recommend GCUndoManager replacement for NSUndoManager.

IOS Swift how can stop re-creating cells on drag or scroling in tableview

I am Creating a tableview using custom cell with textfield. When i enter text in tableviewcell textfield and when i scroll the tableview the data is changing . Means re painting cells . How can i stop reloading cell on drag or scroll in IOS 8 swift
Thanks
If your want your cell not re-used, try to make it a subclass of UITableViewCell with a unique identifier, and do not use the identifier with other cells. I haven't test it yet, just hope it will solve your problem.
Ps. If the textfield's text is still overwritten, make a check at the cell's class file (like making an if-else statement checking if the textfield's text is empty).
Detailed workflow:
In cellForRowAtIndexPath(), after you dequeue the cell, normally you will set some property of your custom cell to refresh the data it holds. To implement this, you need to add a didSet observer on the property at the cell's class file. To achieve the goal you want, you can also add the checking code in the didSet observer.
In Your case. You need to customize your keyboard.
Add [Prev][Next] buttons on top of the keyboard and avoid scrolling.
Basically this idea is useful in form based app. May be your doing that kind.
And yes, Stop relaoding of cells is not good to app. If you will implement this. Apple will not approve your app. So avoid this kind of stuffs.
This is how cells work in a UITableView. The standard implementation of the cellForRowAtIndexPath: method dequeues cells and reuses them.
And ideally your app should save the text from the text fields and change the correct text in the cells depending on their indexPath in the same method's implementation.
If you do not want to do that, a dirty workaround would be to create a new cell every time in the cellForRowAtIndexPath: method instead of dequeuing rows.*
*Do not do this unless absolutely necessary. This is very bad coding practice

Editing custom NSCell

I'm in the process of creating a custom NSCell, which will work like the shortcut capture cells in XCode, and trying to figure out how to intercept edit requests (for instance, when a user double-clicks a cell). Is there some way to determine that an edit is being initiated?
Are you looking specifically to detect a double-click in a cell? If so, setDoubleAction:(SEL)aSelector is what you're looking for.
Or is the question more generically about detecting when a cell will enter 'editing' state? In that case, see the table delegate method tableView:shouldEditTableColumn:row:

RootViewController need to resort/reload data array xcode 4.3

I'm implementing an example, in that example, I read in data from a database, put it in an array, sort it, and it's displayed using the RootViewController. The DB read and array load happen before the RVC code. So, it works, I get the data in the window created by the RVC and there's a nav controller there as well.
I want to add a button or something to the nav controller so that when you hit it, it sends a value back to the RootViewController.m file, then based on that value, I want to resort the array and display it once again in the RootViewController window.
I'm not sure how to do this. What changes would I have to make to the .xib and the RootViewController.m file?
Please, I'm a confused nube. %-0 Thank you very much.
There's a fair amount to this, so I'll give some general points and if any of them cause problems, it may be easier to work out smaller details.
In you RVC's viewDidLoad method, you can create a button and set it as the right or left button in your controller's navigationItem.
You can associate a tap on that button with a method in your controller that can do whatever you want when the button is tapped. (But a button doesn't send values, really, so you may have to explain more about that idea.)
I assume the RVC has a table view if you're showing array contents, so once the array (mutable array, I'd assume) is re-sorted, you can tell the table view to reload its data.
In answer to your secondary question, once you have resorted your array (or generally updated your data however you wish) you can force the table view to reload programmatically
[tableView reloadData];
Where 'tableView' is your instance variable pointing to your table view

NSTableView unable automatically reload data

Can I do that NSTableView do not respond For automatically reloadData? for example when I click on hide program window, or some sing else? Another words update data in table must implement only when I call realoadData: method?
ps I sink may some method like - unableReload or else, but I can't find it(
I'm find the answer.
for solve this situation Focus Ring of TableView must be 'None':
[tableView setFocusRingType:NSFocusRingTypeNone];

Resources