IOS开发错误汇总及解决方法
一、今天调试程序的时候,出现了一个崩溃,信息如下:
2013-02-01 09:05:23.929 SD4iPhone[627:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (5) must be equal to the number of sections contained in the table view before the update (5), plus or minus the number of sections inserted or deleted (0 inserted, 1 deleted).'
*** First throw call stack:
(0x2424052 0x961d0a 0x23cca78 0x14822db 0x18d4257 0x18df518 0x18df593 0x9699b58 0x12111 0x2425e72 0x14119ef 0x23f897f 0x235bb73 0x235b454 0x235adb4 0x235accb 0x2801879 0x280193e 0x1850a9b 0x20c22 0x2a05)
terminate called throwing an exception(lldb)
我要做的是一个table有几个section,每个section都存放一个个人地址,最后一个section是添加个人地址用的,如果地址数量达到5个,则最后一个添加新地址的section不显示。
之前section个数是这样给的:
。这个错误的意思是说:我删除之前有5个section,删除之后section数量不变(由于我需要重现添加新地址这个section就导致section数量不变)。这是矛盾的,所以xcode就给我报错了。
我的解决办法是:定义了一个局部变量sectionCount,未作删除操作时,它的数量就是
-->(勾上Enable Zombie Objects)然后再次运行,可以看到这样的打印信息:
可以看出应该是一个table过度释放了(运气好的话会在代码中直接指出你崩溃的那一行),然后去找那个table在哪过度释放了,这样问题就解决了。(当然了,这个方法并不是百试百灵
,有时候你还得一步步的跟踪,调试
)
待续。。。