IOS - Getting a strange error: unrecognized selector sent to instance in UITableView

Introduction

In my current application, I have a UITableView that contains custom cell objects. Custom UIViewCellObjects are simply subclassed from the standard UITableViewCell class. Custom cells contain information about the start of background loading and update them using things like percent complete, etc.

Custom cell objects listen for NSNotifications from loading processes running in the background, and when they receive a notification, they simply update their own view controls with new information (for example, percent load).

Now that the loading process is complete, I re-order the array of active loading objects and reload the tableview as follows:

-(void) uploadFinished: (NSNotification*)notification { NSDictionary *userInfo = [notification userInfo]; NSNumber *uploadID = [userInfo valueForKey:@"uploadID"]; if (uploadID.integerValue == uploadActivity.uploadID) { [[ApplicationActivities getSharedActivities] markUploadAsFinished:uploadActivity]; [parentTable reloadData]; [self setUploadComplete]; } } 

Now this method takes place in tableviewcell objects, and, as you can see, they call their own UITableView to reload data immediately after sorting the array. The markUploadAsFinished method simply reorders the array, so all ready-made downloads are placed at the top, so it will be displayed this way in a UITableView.

Problem

Now the problem is that when you call this method, sometimes the following error occurs: "NSInvalidArgumentException", reason: '- [CALayer tableView: numberOfRowsInSection:]: unrecognized selector sent to the instance

I donโ€™t get this all the time, sometimes the whole process runs fine, and ready-made downloads appear at the beginning of the UItableview, and in other seemingly random cases this fails. I really donโ€™t understand what is going on here.

Custom cells are loaded from a .NIB file as follows:

  UploadCell *cell = [activeUploadsTable dequeueReusableCellWithIdentifier:@"UploadProgressCell"]; if (cell == nil) { [[NSBundle mainBundle] loadNibNamed:@"UploadCellView" owner:self options:nil]; cell = customCell; } 

Is there anyone who could understand what is going on here?

EDIT

First of all, I found this error to appear right in the line where: reloadData p>

called inside custom cell objects.

In addition, it seems that the instance that it sends to the methods may change. I also got this error:

 'NSInvalidArgumentException', reason: '-[UIScrollViewPanGestureRecognizer tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 

I really donโ€™t know what is going on here.

+4
source share
2 answers

'- [CALayer tableView: numberOfRowsInSection:]: unrecognized selector sent to the instance

You have a bad pointer. It looks like your table data source is being freed while the table still exists. The table does not save its data source, as this may create a save cycle. If you do not care about maintaining the data source while using the table, the table may work with a pointer to an object that no longer exists. In this case, it looks like the CALayer object is subsequently created at the same address. When the table later sends its "data source" message to get the number of rows, this message is delivered to this level, which (obviously) does not have the -tableView:numberOfRowsInSection: method, and an error occurs.

+6
source

According to my words, you run the boot process method in the background, I think this is a different thread than the main thread. And, according to my knowledge, when you are dealing with UIKIT objects, you have ruins in the main topic.

But this problem does not occur every time, because for some time you switch to another thread in the main thread, therefore its work is beautiful and for some time not. so the problem arises

0
source

Source: https://habr.com/ru/post/1397137/


All Articles