ra1028 / Former

Former is a fully customizable Swift library for easy creating UITableView based form.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

removeUpdate crash on items with inline

OozoraHaruto opened this issue · comments

My Code:

    private let itemDateTime = InlineDatePickerRowFormer<FormInlineDatePickerCell>() {
        $0.titleLabel.text = "Data (Date & Time)"
        $0.titleLabel.textColor = .formerColor()
        $0.titleLabel.font = .boldSystemFont(ofSize: 15)
        $0.displayLabel.textColor = .formerSubColor()
        $0.displayLabel.font = .systemFont(ofSize: 15)
        }.inlineCellSetup {
            $0.datePicker.datePickerMode = .dateAndTime
    }.displayTextFromDate(String.mediumDateShortTime)

    private let itemNumber = StepperRowFormer<FormStepperCell>(){
        $0.titleLabel.text = "Data (Number)"
        $0.titleLabel.textColor = .formerColor()
        $0.titleLabel.font = .boldSystemFont(ofSize: 15)
        $0.displayLabel.textColor = .formerSubColor()
        $0.displayLabel.font = .systemFont(ofSize: 15)
        }.displayTextFromValue { "\(Int($0))" }

    private func addStoredDataRow(_ newRow:String,belowRow row: RowFormer){
        self.former.insertUpdate(rowFormers: [itemDateTime as RowFormer], below: row, rowAnimation: .fade)
    }
    private func removePreviousStoreDataRow(){
        self.former.removeUpdate(rowFormers: [itemDateTime as RowFormer], rowAnimation: .fade)
    }

It returns this error

** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 5 from section 0 which only contains 5 rows before the update'
*** First throw call stack:
(
	0   CoreFoundation                      0x000000010dbb7d4b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x000000010b4e021e objc_exception_throw + 48
	2   CoreFoundation                      0x000000010dbbbe42 +[NSException raise:format:arguments:] + 98
	3   Foundation                          0x000000010b07566d -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
	4   UIKit                               0x000000010baebc81 -[UITableView _endCellAnimationsWithContext:] + 6554
	5   Former                              0x000000010ab80fed _TFC6Former6Former12removeUpdatefT10rowFormersGSaCS_9RowFormer_12rowAnimationOSC23UITableViewRowAnimation_DS0_ + 717
	6   Help me remember                    0x000000010a906461 _TFC16Help_me_remember21AddNoteViewControllerP33_77E2466EC3256EA1B6E259688F5902C826removePreviousStoreDataRowfT_T_ + 401
	7   Help me remember                    0x000000010a906060 _TFFC16Help_me_remember21AddNoteViewControllerP33_77E2466EC3256EA1B6E259688F5902C89configureFT_T_U8_FGC6Former16InlinePickerItemP__T_ + 624
	8   Former                              0x000000010abaec6f _TTRG0_RxCSo15UITableViewCellx6Former23InlinePickerFormableRowrXFo_oGCS0_16InlinePickerItemq____XFo_iGS2_q___iT__ + 31
	9   Former                              0x000000010abb3c63 _TPA__TTRG0_RxCSo15UITableViewCellx6Former23InlinePickerFormableRowrXFo_oGCS0_16InlinePickerItemq____XFo_iGS2_q___iT__ + 131
	10  Former                              0x000000010abb312e _TFC6Former21InlinePickerRowFormerP33_6A299C3DDCBB01395AC4594859BB2B0B12valueChangedfT10pickerItemGCS_10PickerItemq___T_ + 2398
	11  Former                              0x000000010abb50ea _TPA + 26
	12  Former                              0x000000010abb876f _TTRG0_RxCSo15UITableViewCellx6Former17PickerFormableRowrXFo_oGCS0_10PickerItemq____XFo_iGS2_q___iT__ + 31
	13  Former                              0x000000010abb8853 _TPA__TTRG0_RxCSo15UITableViewCellx6Former17PickerFormableRowrXFo_oGCS0_10PickerItemq____XFo_iGS2_q___iT__ + 131
	14  Former                              0x000000010abb97b5 _TFC6FormerP33_EABB0162137B5A80359DB051B72B0E158Observer10pickerViewfTCSo12UIPickerView12didSelectRowSi11inComponentSi_T_ + 405
	15  Former                              0x000000010abb984a _TToFC6FormerP33_EABB0162137B5A80359DB051B72B0E158Observer10pickerViewfTCSo12UIPickerView12didSelectRowSi11inComponentSi_T_ + 74
	16  UIKit                               0x000000010b9930fd -[UIPickerView _sendSelectionChangedForComponent:notify:] + 104
	17  UIKit                               0x000000010b99334e -[UIPickerView _sendSelectionChangedFromTable:notify:] + 370
	18  UIKit                               0x000000010c1603de -[UIPickerTableView _scrollingFinished] + 187
	19  UIKit                               0x000000010c1605ce -[UIPickerTableView scrollViewDidEndDecelerating:] + 30
	20  UIKit                               0x000000010baa043d -[UIScrollView(UIScrollViewInternal) _scrollViewDidEndDeceleratingForDelegate] + 91
	21  UIKit                               0x000000010ba9cf7e -[UIScrollView(UIScrollViewInternal) _stopScrollDecelerationNotify:] + 316
	22  UIKit                               0x000000010ba9d1d5 -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 505
	23  UIKit                               0x000000010ba9511f -[UIScrollView _smoothScrollWithUpdateTime:] + 3304
	24  QuartzCore                          0x0000000113778895 _ZN2CA7Display15DisplayLinkItem8dispatchEy + 57
	25  QuartzCore                          0x0000000113778755 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 449
	26  CoreFoundation                      0x000000010db49db4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
	27  CoreFoundation                      0x000000010db49a43 __CFRunLoopDoTimer + 1075
	28  CoreFoundation                      0x000000010db495ca __CFRunLoopDoTimers + 250
	29  CoreFoundation                      0x000000010db412f1 __CFRunLoopRun + 2065
	30  CoreFoundation                      0x000000010db40884 CFRunLoopRunSpecific + 420
	31  GraphicsServices                    0x0000000113751a6f GSEventRunModal + 161
	32  UIKit                               0x000000010b9afc68 UIApplicationMain + 159
	33  Help me remember                    0x000000010a90c1df main + 111
	34  libdyld.dylib                       0x000000010f1ab68d start + 1
	35  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

I'm sure my code works well as if i replace itemDateTime with itemNumber it works well with removing and inserting multiple times.

Sorry I am still learning swift so I can't help with debugging it.

I have the same problem with InlineDatePickerRowFormer and removeUpdate.

Fixed in #64