简体   繁体   English

重新加载tableView时出现奇怪的错误

[英]strange error when reload tableView

I have a very general table view. 我有一个非常普通的表格视图。

when it is refreshed, it will go to fetch list of objects from Parse. 刷新后,它将从Parse中获取对象列表。 Analyze these data in a dispatch_async queue, then refresh table view. 在dispatch_async队列中分析这些数据,然后刷新表视图。 Most time, it has no problem, but some time reloadData() crash 大多数时候,它没有问题,但是有一段时间reloadData()崩溃

在此处输入图片说明

Is it crashes because the tableView is reloading data when I call it? 是因为我调用tableView时正在重新加载数据而导致崩溃吗? (when the tableview is init, reloadData may be called automatically) How to avoid this error? (当tableview初始化时,reloadData可能会自动调用)如何避免此错误? ( there is no error message in console ) (控制台中没有错误消息)

EDIT: I tries to put ? 编辑:我试图把? , but does not work ,但不起作用

在此处输入图片说明

This happens when your tableView (or whatever object you're sending the message to) is nil. 当您的tableView(或您要将消息发送到的任何对象)为nil时,就会发生这种情况。 So sometime before your async call dispatched this on the main queue, your tableView got dealloacted. 因此,在异步调用在主队列上调度此事件之前的某个时候,tableView被释放了。

Check this link out for some info: 查看此链接以获取一些信息:

http://www.touch-code-magazine.com/how-to-debug-exc_bad_access/ http://www.touch-code-magazine.com/how-to-debug-exc_bad_access/

You will get EXC_BAD_ACCESS error mostly in the following scenarios: 在以下情况下,您通常会得到EXC_BAD_ACCESS错误:

You are trying to access an object that is not initialized. 您正在尝试访问未初始化的对象。

You are trying to access an object that no longer exists. 您正在尝试访问不再存在的对象。 Either it's being released or it's nil. 它要么被释放,要么为零。 In ARC mode, make sure you take ownership of the object that you want to use. 在ARC模式下,请确保您拥有要使用的对象的所有权。 You are passing an message to an object that the object doesn't understand. 您正在将消息传递给该对象无法理解的对象。

It can also happen for bad typecast. 错误的类型转换也会发生这种情况。 Like the lines below where I am trying to access an int with %@ in stead of %d. 就像下面我试图用%@而不是%d访问int的行。

 int myAwesomeInt = 9;
 NSLog(@"%@", myAwesomeInt);

How to debug: 如何调试:

Identify what you did that caused the crash. 确定造成崩溃的原因。 Did it crash while view of a particular view controller didLoad or in a delegate method or on a particular action. 它是否在特定视图控制器didLoad的视图中或在委托方法中或在特定操作上崩溃了? That will often help to find the object that is casuing the error. 这通常将有助于找到引起错误的对象。

(In your case look at what specifically happens when you are reloading the table. Do a stack trace line by line and see what your code is doing during a reload) (在您的情况下,请查看重新加载表时发生的具体情况。逐行执行堆栈跟踪,并查看重新加载期间代码的作用)

Most of the time “NSZombies” can help to identify the dead object. 大多数时候,“ NSZombies”可以帮助识别死物。 You can enable NSZombies by editing your scheme Product -> Edit Scheme -> Diagnostics. 您可以通过编辑方案产品->编辑方案->诊断来启用NSZombies。

If you still don't find the root cause then always go backwards from child view controller to parent view controller to see what object needs to be retained or what message needs to be passed properly. 如果仍然找不到根本原因,那么请始终从子视图控制器转到父视图控制器,以查看需要保留哪些对象或正确传递什么消息。 Look into Static Analyzer and Instruments for advanced debugging. 查看静态分析器和仪器进行高级调试。

Credit: The Basic Troubleshooting guide 信用: 基本故障排除指南

Hope this helps. 希望这可以帮助。 Good Luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM