How can I maintain display order in UITableView using Core Data?

后端 未结 4 1504
说谎
说谎 2020-12-12 18:01

I\'m having some trouble getting my Core Data entities to play nice and order when using an UITableView.

I\'ve been through a number of tutorials and other questions

4条回答
  •  有刺的猬
    2020-12-12 18:28

    (This is intended as as comment on gerry3's answer above, but I am not yet able to comment on other users' questions and answers.)

    A small improvement for gerry3's - very elegant - solution. If I'm not mistaken, the line

    otherObject.displayOrderValue += delta;
    

    will actually perform pointer arithmetic if displayOrderValue is not of primitive type. Which may not be what you want. Instead, to set the value of the entity, I propose:

    otherObject.displayOrderValue = [NSNumber numberWithInt:[otherObject.displayOrderValue intValue] + delta];
    

    This should update your entity property correctly and avoid any EXC_BAD_ACCESS crashes.

提交回复
热议问题