Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

cellForAtIndexPath was not called in ViewDidLoad()?

Hello Everybody,


I have made a simple Cat App thats parsing by NSXMLParserDelegate protocol a XML file from public API and shows photos of cats in a TableView. It works fine, but I am trying some refactoring. I have made a CatsDataSource as! NSObject class when it does parsing and calling tableView functions which are part of UITableViewDataSource. I have put in my main ViewController an instance of CatsDataSource class and set my IBOutlet catsTableView.dataSource = instance of CatsDataSource , also for delegate. It works but partially. Only when I call reloadData() from a random function, which is a function that randomize cats pictures in the tableView.

I have found that tableView cellForRowAtIndexPath func was not called at all in ViewDidLoad(). It’s only called when click random function.(which is IBAction func.)

Thnaks.

Bojan

Mac mini (Late 2014), iOS 9.3.1, Swift

Posted on May 5, 2016 3:44 AM

Reply
Question marked as Best reply

Posted on May 6, 2016 12:16 PM

Bojan

1. function viewdidload is ***only called one time*** when the viewcontroller is constructed, focus *ONLY ONE TIME*

2. when uitableview is constructed, function cellForRowAtIndexPath is called, but only some rows, which is shown, is called

Ex: you have 30 rows in tableview, but only 3 rows is shown => cellForRowAtIndexPath is called 3 times.

when load scroll to end of tableview => cellForRowAtIndexPath is called again to load next row to show

Hope to help your problem.

Cheers ~.~

2 replies
Question marked as Best reply

May 6, 2016 12:16 PM in response to BojanSwift

Bojan

1. function viewdidload is ***only called one time*** when the viewcontroller is constructed, focus *ONLY ONE TIME*

2. when uitableview is constructed, function cellForRowAtIndexPath is called, but only some rows, which is shown, is called

Ex: you have 30 rows in tableview, but only 3 rows is shown => cellForRowAtIndexPath is called 3 times.

when load scroll to end of tableview => cellForRowAtIndexPath is called again to load next row to show

Hope to help your problem.

Cheers ~.~

cellForAtIndexPath was not called in ViewDidLoad()?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.