Assertion failure when i use the Add Function

前端 未结 3 684
梦如初夏
梦如初夏 2021-01-03 15:31

In a table, I have 3 indexes which calls each a function. In each function, there is an add button that adds data into CoreData. First 2 works, but when i press the 3rd inde

3条回答
  •  离开以前
    2021-01-03 16:18

    The error message tells you the problem:

    Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted). with userInfo (null)**

    In your table section (0), you started with zero rows i.e. an empty section. Then you added 1 row so the section(0) row count should be 1 but numberOfRowsInSection: is returning zero.

    There are three probable causes for this problem:

    1. You didn't freeze the tableview with beginUpdate in controllerWillChangeContent: such that the tableview tries to redraw itself before the update completes.
    2. Your numberOfRowsInSection returns the wrong row count for the section.
    3. You are inserting one managed object multiple times or you have a validate on insert/update that fails.

    Can't tell you the actual problem without the code.

提交回复
热议问题