UITableView reloadData does not make UITableView reload its data - ios

I have methods implemented for datasources like heightForHeaderInSection or cellForRowAtIndexPath. I have a MasterView - DetailView class implementation which implemented on different class. When I open the MasterView which will then open a DetailView for an item I select on MasterView, the DetailView will call all the datasources (touch the breakpoints). But after I return to MasterView and select another item, it will open DetailView again but show the old data, and all the datasources breakpoints are not touched at all. I have called the [detailTableView reloadData] manually from MasterView after populating DetailView's properties with new data and before bring the DetailView to screen, but the table won't refresh. What went wrong?

Related

How can I integrate an UITableView or UITableViewController into a UIPageViewController?

I would like to have an UIPageViewController with several pages where all of them are instances of UITableView or even UITableViewController, but I am a bit lost on how to do this. I have tried adding them from the Interface Builder, but this doesn't seem to be possible.
I'm assuming you have your PageVC and you have connected VCs. Suggest use standard VCs in preference to TableVCs:
This is how I setup a TableView in a View Controller
In Storyboard:
Drag a TableView into the View area. Select the VC icon (leftmost) in the VC header in the storyboard and in Attributes inspector ViewController layout uncheck Adjust scroll view inserts (this gets rid of some extra space at the top of the tableview.
Click the tableview to select it and cntl-drag from the tableview to again the VC icon and it will offer connect to the TableViewDelegate and to the TableViewDatasource. Select one and repeat for the other.
Then drag a TableViewCell into the TableView. Select it and, in the Attributes Inspector, set the identifier to Cell (or whatever but same as in CellForRowAtIndexPath - see below).
Next, in the XCode's top bar click the assistant editor button to get 2 windows. Have storyboard in left and the View controller in the other.
For simplicity, use a separate Swift file for each VC.
So create an outlet by dragging from the TableView in Storyboard to the VC code call it tableView (at least for now). We're done with Storyboard so can go back to the Standard Editor and focus on the VC's code.
Next, add the 2 tableview protocols UITableViewDelegate and UITableViewDataSource to the VC's source class statement.
Do an Xcode Cmd-S (Save); Shift-Cmd-K (Clean); Cmd-B (build) at this point to give the autocomplete process a nudge.
Lastly, create the 3 main TableView methods - and they should autocomplete:
NumberOfSectionsInTableView.....
return 1 // for now
NumberOfRowsInSection.....
return array.count // Assuming your data is in an array called array
CellForRowAtIndexPath.....
then
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel?.text = array[indexPath.row] //- assuming string array
return cell
That should setup your functioning tableview - Repeat for other VC(s).
Tailor accordingly...

IOS: How do I populate a UITableView which is within a nib?

I have a nib file in which there is a UILabel and a UITableView.
So I've created 2 outlets - one for the label the other one for the UITableView.
Then I've created a subclass of TableViewController which knows how to populate a UITableView the way I want to. With it I'm going to populate that my UITableView.
Then in viewDidLoad of the controller for that nib file I do
[myTableViewController setView: myTableViewOutlet]
I expect the functions numberOfRowsInsection and other such from myTableViewController will be called after that so my UITableView gest populated.
But this does not happen and my UITableView remains empty..
What do I do wrong?
Two things I can think of that might be missing:
Set data source and delegate of the tableview to the controller;
Call reload data method on the tableview to trigger a reload.

When UITableView's data is loaded? What's time tableview call its delegate methods. After viewWillAppear?

I am wondering when UITableview's data is loaded.
I mean, when I create a UITableView, then normally I will set its datasource and delegate. After that, this tableview will be added as a subview.
However, If I don't call reload method, I don't know when the tableview know it needs to ask its delegates and show the data. In another word, since a view has no viewWillAppear methods, what's the exact time that a tableview ask its delegate and show the data?
I've tried some what:
In viewDidLoad, I create a tableview, added it as subview, but not setting its delegates. Obviously, the data is not loaded.
Then I set its delegate once I tap a button, its data is not loaded.
But when the tableview's controller's viewWillAppear is called again (when the controller disappears and appears again), the data is loaded.
There is no universal set time, because a UITableView's display data is in cells, and the cells are dynamically loaded. (also probably reused) You can call reload, but that just instructs the table to refetch the data on visible cells. The question remains: why do you need to know? If you need to intercept the data before it's loaded into a cell, do it in cellForRowAtIndexPath, where you're supposed to stuff the data into the cell.

iOS UITableView: didSelectRowAtIndexPath not reacting for clicks everywhere

I have several UITableViews which should segue further in my navigation controller. First I've created the segues directly from the table view cells. But then I've noticed that in the smaller cells if you click on the label or somewhere, this method didSelectRowAtIndexPath doesn't get triggered. Only if you click on an "empty" space in the cell.
So I've created the segue for the whole view and just called performSegueWithIdentifier in the didSelectRowAtIndexPath method.
But still the same problem. Is this only my impression that you have to click on empty parts or onto the right side of a cell to perform a segue or is something else wrong? Or how could I make the whole cell reactive?
You might try turning off User interaction enabled for the labels in your cell.

UITableView does not show any cells after UIViewController popped then returned to

I have a UITableView within a UIViewController and am having an issue where the table displays ok on first load via a segue, but when you push the back button on the header, then go forward to the UIViewController again the table is blank.
I'm using a custom classed tableview, but the default methods like numberOfRowsInSection and cellForRowAtIndexPath are being called on the second load. In fact, the cellForRowAtIndexPath method is returning a cell with the cell.textlabel.text properly set as expected. numberOfRowsInSection is returning the correct number of rows. And numberOfSectionsInTableView is returning 1. But when everything finishes loading there's nothing in the table.
I'm using storyboards and the prototype cell is set up with a reuse identifier. I've tried calling [tableView reloadData] from the view controller in both the viewDidLoad and viewWillAppear methods.
The datasource and delegate are both set ok (I think - or else it wouldn't work first time it's loaded).
I'm not doing anything different (that I can see) to other tables in my app, apart from using the UITableView within a UIViewController rather than using a UITableViewController. Is there anything that I'm missing that the UITableViewController handles automatically?
I'm a bit stumped - any ideas would be much appreciated!
EDIT: The custom class used in the UITableView isn't under ARC control, as it's an old library that I'm using. I'm using the -fno-objc-arc flag. Could this be something to do with it?

Resources