Table View's Delegate Method Cell for row at not called - ios

I am using a table view and set the delegate and datasource in view will appear.
return 1 in number of section and 5 in number of rows but cell for row at delegate method is not called. I checked my storyboard view cell's ideantifier and class name is correct. Pls help

There are few things that may be or are wrong with your code. First one is that you should setup the delegate in storyboard or ViewDidLoad (in storyboard drag from tableView to the ViewController instance and select both - delegate and datasource) The other thing is that you may made a typo when writing the code for delegate methods(always use automatic method completion feature in xcode)

After setting delegate and datasource , reload the table view.

Related

"cellForRowAtIndexPath" for a tableview inside alertviewcontroller not called

I am adding a tableview inside an alertviewcontroller , I have given delegate and datasource to the table. All delegate and datasource methods except cellForRowAtIndexPath are called. I have return a static value for number of rows in section to prevent 0 rows. Still it is occurring.
You are not supposed to modify the view hierarchy of a UIAlertController. You’ll either need to create your own view controller that mimics an alert controller or find a framework that does that for you.
To quote the Apple docs:
The view hierarchy for this class is private and must not be modified.
I would suggest you to create a custom UIViewController, add required functionality and present it as a Form Sheet. Refer https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/PresentingaViewController.html

UITableView reloads on show view controller

Please help me to understand why table view reloads on view controller start. I setup outlet for table via storyboard and data source, delegate. I did't call tableView reloadData method.
So When view controller starts '..numberOfRowsInSection' and other table view delegates methods called.
as Apple docs say:
UITableView overrides the layoutSubviews method of UIView so that it
calls reloadData only when you create a new instance of UITableView or
when you assign a new data source. Reloading the table view clears
current state, including the current selection. However, if you
explicitly call reloadData, it clears this state and any subsequent
direct or indirect call to layoutSubviews does not trigger a reload.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/
If you really do not need its reloading, create your tableView as a lazy variable and add it to a view programmaticaly when you need it.

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.

How can I access a table view delegate methods of one controller from another ios

Here is the issue.
We have a pageview controller which creates view from another view controller that has a tableview in it. So after the view is created we would like to click on a cell of the tableview to run a function. Note that the tableView:didSelectRowAtIndex is not working.
I have put the delegate for the table view as the second one as I need to create header and footer for the table. I tried putting tableView:didSelectRowAtIndex in the view controller but it didn't work.
Then I thought of including a tapGesture for each of the cell but I need to show the details based on parameter from both the controllers. Hope you could help in this
Did you conform to table protocols of UITableViewDelegate and UITableViewDataSource ?
I think you forgot to set DataSource and Delegate method for table in perticular view.
tableView.dataSource = self;
tableView.delegate = self;
Write above code and check. You get all the delegate and datasource method for tableview.
I had accidently put the selection to no selection in stroyboard. The issue is fixed now.
Thanks for looking into this.

IOS SplitView TableViewController query

I have one SplitViewController with default settings added into an xib file. Its Table View controller i defined as another class (in Identity Inspector) as a TableView Controller class I created.
Now I have put some code in its
...numberOfRowsInSection:(NSInteger) section
and ...cellForRowAtIndexPath:(NSIndexPath *) indexPath
It works fine with total values in its table according to numberOfRows I have defined and elements in cell according to what cells I create and return in the appropriate method.
My question is:
How is table coming into the SplitView because when I customize UITableView in the xib of my TableViewController, its changes do not appear in the SplitView's left section. (I guess that table View is non-customizable? )
Secondly How does iOS initialize that TableViewController class from XIB because I have to put some initialization code that when that TableView is created, do following things. I tried over-riding various init functions it does not call any of those. How can I initialize some data when that TableViewController is initialized?
Thanks.
The table view is customized in the XIB that contains the split view and not in an own XIB file
You can do 2 things: override initWithCoder: (remember to use the self=[super initWithCoder: pattern) or override - (void)awakeFromNib

Resources