Fix "Attempted to call -cellForRowAtIndexPath: on the table view while it was in the process of updating its visible cells, which is not allowed"


Hello guys, Today the title is a little bit long. Because I want to make the title can be searched exactly the same on google searching. This is a warning not a error. So It wouldn't impact to your app if you run it on your device or emulator. The warning appeared on console not in Buildtime as usually in issue navigator.

This warning doesn't give the exact line number where the warning happened. So we need to do breakpoint to check where it's supposed to be. But the warning in console give us a hint. We take the keyword "cellForRowAtIndexPath". So it related to UITableview because "cellForRowAt" is the method that's in UITableVIew.

As you can see my screenshoot of my console above, there's multiple times the warnings happened. It's because of "cellForRow" called many times, not just once. But don't be deceipted to assume that the warning happed in cellForRow method. The warning actually happened in "heightForRowAt", when in the method, it called dequeueReusableCell, the method of UITableview. As you can see in example below.

I just put heightForRowAt inside this gist, so you can focus on what's going on. This code is actually working fine, it will not make your app crash or compile time error. But it will disturb us in console log. It means maybe on the future, there will be something bad in our app. And we don't want it happened.



So, it's so clear. It's bad practice to use this code in our app. We need to find other solution. Don't call cell inside heightForRowAt. My solution is to create cell variable public in this class and call it inside heightRowAt. So finally the warning will be disappeared, and the app will be happy no worrying warning at all.

Thanks for visiting my simple blog, I hope I can post article every week and give you more good post. If you have any question, feel free to ask me on comment below or send me email. Happy day.

Popular posts from this blog

How to restart the app with flutter Android and iOS

Missing system image Android Studio solution

How to have ConstraintLayout inside ScrollView and ScrollView inside ConstraintLayout Android