numberOfRowsInSection not called after reloadData - iphone

I've seen various similar posts to this but none seem to match my situtation/solve the problem.
I have a tableview whose delegate and datasource are set to the VC it sits within.
On load this happily calls all the usual methods:
numberOfSectionsInTableView
numberOfRowsInSection
cellForRowAtIndexPath
however at this point the array containing my data is empty.
Once it is populated (after location lookup) [tableView reloadData] is called. This successfully fires:
numberOfSectionsInTableView
but neither of the following are recalled
numberOfRowsInSection
cellForRowAtIndexPath
I have even tried returning different results (0/1) in the numberOfRowsInSection method to try and force it with no result
Thanks for any help

I found the error.
The client had been playing with the code and changed the viewForHeaderInSection so that in some cases it was returning nothing (not even nil).
This must have prevented the other methods from firing, despite their being no exception or console log warning.

Related

Purpose of tableView(_:objectValueFor:row:)

The documentation for the NSTableViewDataSource protocol says
This method is mandatory
and if you create a new NSTableViewDataSource the compiler asks you to provide this method as well as numberOfRows(in tableView: NSTableView).
So far, so good. And if you provide it, it promptly gets called once for every row... but if you delete it, the table seems to work every bit as well as it does without. There seems to be absolutely no connections in a view-based table to this method: in the NSTableViewDelegate's tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) method, I return new views based on the content array of my datasource, and if I stick a bunch of nonsense data into objectValueFor: row (up to and including returning the same string - my table objects are not strings) is has no effect whatsoever because I'm setting the values of my NSTableViewCells in viewFor tableColumn:.
If I'm handling selection changes (and anything I want to do with objects) by retrieving the corresponding value from the datasource directly (e.g.)
func tableViewSelectionDidChange(_ notification: Notification) {
print(dataSource.allItems[tableView.selectedRow])
}
is there any reason to implement this method? I cannot see any point where that object is actually used, and it feels like an artefact from cell-based tables.
I don't want to break my code by leaving out a necessary method, but since I'm about to try something weird and wonderful with a custom datasource, I also don't want to overcomplicate my code with a method that gets called, but the result of which seems completely meaningless.
If the cell view responds to setObjectValue:, then the table view calls that method and passes in the object value for the row that was obtained from tableView(_:objectValueFor:row:).
NSTableCellView does respond to that method and is a common cell view class. NSTextField does, too; it actually inherits it from NSControl.
In your case, your cell view either doesn't have an objectValue property or, more likely, you're just not using it.
One common configuration is to use NSTableCellView as the cell view and then use bindings to bind the subviews to key paths going through its objectValue property.

How to make accessible a automatically created dictionary inside of textDidChange(_:) as data for the NSTableView functions?

I had the suggestion to use function textDidChange() to perform code inside this function automatically. It is working. It is in my Controller class.
Now I am going to use this approach for creating automatically, inside of textDidChange(), a dictionary variable from text, when user is typing in NSTextView. Then, I need this dictionary for the NSTableView functions, to display a Table in application corresponding to the text typed by user.
Question is how to make accessible this dictionary from textDidChange(_:) function for the NSTableView functions like
numberOfRowsInTableView(tableView: NSTableView)
and
tableView(tableView: NSTableView, viewForTableColumn tableColumn:
NSTableColumn?, row: Int) -> NSView?
All in the same Controller class.
I am not sure if same dictionary will be your datasource for the tabelview .But for this method you can simply call reloaddata function of tableview to after updating your tableview datasource .

Duplicate tableview cells in Swift

I have a tableview that is populated using a Parse query. However, all of the cells are loaded with the first object from the query results array. For example, if the query returns [User1,User2] the two cells in the tableview will show "User1". What am I doing wrong?
Here's a gist of the file:
https://gist.github.com/jtansley/2329c6fa4baa63f48ee2
Hopefully the issue is obvious to experienced programmers.
Thanks!
After reading your code, I think you don't know that findObjectsInBackgroundWithBlock is a function run in another thread but main thread.
Therefore, in func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell , your change in UI would be wrong.
One more things, to improve your app performance, you shouldn't query in cellForRowAtIndexPath! Do your queries in viewDidLoad instead. Fill your database on Parse to an array, then load it inside cellForRowAtIndexPath function.
I couldn't code for you since I'm hanging out with my gf. ;)
Hope this help.

iPhone UITableView within UITableViewCell

I want to create an layout in that I want to put UITableView(SubTableView) inside UITableViewCell of the first UITableView(MainTableView). The problem which I am facing is that when I call the Data Source method of MainTableView, then all the DataSource Method are initialised but when cellForRowAtIndexPath method is executed then my SubTableView in not calling its DataSource Method for particular row of the MainTableView.
Instead it calls the DataSource Method of MainTableView and then it calls the DataSource Method for the SubTableView. My concern is that I want to call DataSource Method for SubTableView when cellForRowAtIndexPath method is executed for the MainTableView for particular row.

numberOfRowsInSection did not return mutable array length

I am new to iphone development. numberOfRowsInSection method of UITableViewController executed before parsing the XML node so that this method return value as zero, but this method should be return value of number of rows with data.
please help me
thanks.
After parsing of your XML data is finished call [myTable reloadData]; - it will force your UITableView to reload the data shown and thus all necessary methods (including numberOfRowsInSection) to get called.
I've had a similar problem before, and it was because I was passing the array/dictionary to the controller from the appdelegate. Unfortunately, after the app delegate went out of scope, the array was lost.
Try doing an array copy,
NSArray data = [NSArray arrayWithArray: passedInArray];
Sorry, don't have my trusty macbook on me to check the code, but you get the drift.
I solved this problem via made connection between tableView reference and file owner in interface builder.