Keep a record of all the stupid things you do. Everybody see officer see laugh!!
Today I encountered a problem when building the page. After all the data was set, tabView did not display it. After the break point, I found that the TabView DataSource did not use cellForRowAtIndexPath method (details are as follows).
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
Copy the code
Analysis of reasons for not using this method:
DataSource not set
First reaction is to see whether to set up the self. The tableView. DataSource = self; If the data source is not set up, there will be no data, but it is set up.
There is no data in the data source
The second possibility is that the array of the data source is empty, i.e
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
Copy the code
Both methods have a return value of 0, but the breakpoint check shows that there is data.
TableView width or height = 0
In this case numberOfSectionsInTableView and numberOfRowsInSection are performed, and the cellForRowAtIndexPath does not perform. That’s exactly the case, but I already set the frame when I created the tableView, so it’s not the case.
This next meng force, do you still have the fourth kind of possibility, Baidu also only have these several cases. So through their repeated search, and finally found a reason for me to laugh and cry:
High energy ahead !!!!
4, The tableView is not rendered to the view.
Never thought! The fourth condition appears!! Please refrain from laughing!! (We are trained not to laugh, no matter how funny, unless we can’t help it.)
The situation and the third by the same token, when the tableView not rendering to view, the DataSource can go numberOfSectionsInTableView and numberOfRowsInSection method, But will not go cellForRowAtIndexPath method (you do not show, I go 🔨, compensate you a silly force walking happy happy happy? Ps: this idiot is talking about me, hahaha). In a nutshell:
Less [self view addSubview: self tableView]; (Sorry, I couldn’t help it!!)
I forgot about this because I used to xiB drag a lot. (Actually, the first reaction is not DataSource, because DataSource can also xiB drag, but not very good). After finding the reason really is oneself can laugh at oneself dead, ha ha ha!! No wonder there is no baidu, who would have thought that there are people can small stupid force to this degree? That’s me! But what if? So at the risk of being laughed at, write this article for the same careless little confused people to see, so that you can quickly locate the method! Alas ~ strong wind and big waves (in fact, also did not have much) have experienced, do not want to capsize in this small place cough up!!