escoz / QuickDialog

QuickDialog - Quick and easy dialog screens for iOS
http://escoz.com/open-source/quickdialog
Other
3.07k stars 637 forks source link

fix to QMultilineElement to provide 'didEndEditing' delegate call - please add! #657

Open rspreen opened 10 years ago

rspreen commented 10 years ago

QMultilineElement is difficult to use because, unlike the QEntryElement class that it extends, it does not offer a controllerAction to signal the user when the editing is finished. The intention for QMultilineElement is to provide a delegate (QuickDialogEntryElementDelegate).

This would be fine except that it currently never calls the delegate method "QEntryDidEndEditingElement". You only get a delegate call for changes, meaning every single typed character causes a callback. This is very inefficient for cases where the change of the text causes expensive processing; we only want a single call when editing is complete, not for every keystroke of entering text. It also breaks the contract of the delegate that the "didEndEditing" is never called.

This is very simple to fix. In QMultilineElement in the "selected:controller:indexPath:" method, it sets the "willDisappearCallback" for the MultilineTextViewController. This callback should include a delegate callback, like this:

__weak QMultilineElement *weakSelf = self;
__weak QMultilineTextViewController *weakTextController = textController;
__weak QEntryTableViewCell* weakCell = textController.entryCell;
textController.willDisappearCallback = ^ {
    weakSelf.textValue = weakTextController.textView.text;
    [[tableView cellForElement:weakSelf] setNeedsDisplay];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    // ** This is the added code
    if (self.delegate && [self.delegate respondsToSelector:@selector(QEntryDidEndEditingElement:andCell:)]){
        [self.delegate QEntryDidEndEditingElement:self andCell:weakCell];
    }
};

I hope this is helpful, it certainly makes the QMultilineElement far more useful. I love QuickDialog, thank you for maintaining it!