"cellForRowAtIndexPath" for a tableview inside alertviewcontroller not called - ios

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

Related

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

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.

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.

How to use a TableView inside a UIViewController?

I want to add a simple static TableView to my UIView. So i dragged it into my UIView. Added the TableViewDataSource and Delegate Protocols to my ViewController class. Created an outlet to my tableview and connected the datasource and delegate outlets to the viewcontroller.
But i still get an error message which says that Static table views are only valid when embedded in UITableViewCOntroller Instances ? Any Ideas how to solve this Problem ?
PS: I am using UIStoryboards for designing the UI
Use a containerView (drag one onto your UIView) which will link to a UITableViewController instead. You will use the prepareForSegue method to initialize the table view controller.
Oh, and you might want to accept answers that help you or no one will help you anymore.
If you want static cells, in your Storyboard, click on the tableview, then in the inspector, change the Content from 'Dynamic Prototypes' to Static Cells. You can also segue these cells to a new controller without having to set up data sources and delegates for the table.

How to make a callback from a UITableViewController to another UIViewController

I followed this discussion: UITableView issue when using separate delegate/dataSource, and even though I found it super informative and useful, I have a follow up question:
So I've got a similar setup where I have a UITableView within the UIView. The UIView is controlled by it's own UIViewController (let's call it MyUIViewController) and also I moved the delegate and datasource for the UITableView into a separate subclass of UITableViewController (say, MyUITableViewController).
Everything works fine with the tableView.
The question is, how do I make a callback from MyUITableViewController to the MyUIViewController? For example, if the user selects a cell under the tableView which triggers didSelectRowAtIndexPath, I need to update something on the UIView which is actually a parent of this UITableView. So I basically need to send a message to MyUITableViewController. How would I do that?
You can use a delegate pattern in this case. I have a similar answer with sample code in this SO . In your case, the parent view controller is MyUIViewController. And the child view controller is MyUITableViewController.

How can I add more than one UITableView in a UIViewController?

Here is my app.
http://www.flickr.com/photos/baozhiqiang/6943921630/
http://www.flickr.com/photos/baozhiqiang/6943921900/
You can see three buttons at the top of the main screen. When you click it, the gallery will change to next. They are not the same layout style.
I created it by making three ScrollView in a big ScrollView. Code like this:
[backgroundScrollView addSubview:innerNewsScrollView];
[backgroundScrollView addSubview:innerHotScrollView];
[backgroundScrollView addSubview:innerLinkScrollView];
And when click the button, I changed the frame of the ScrollView.
Now there is a problem, when I add more than 100 Pictures(UIButton with image) to the ScrollView, It had crashed. I want to use UITableView replace ScrollView. But how can I Control more than one UITableView in a UIViewController?
Anybody can help me!
Two possibilities:
All the table view delegate methods include the table in question as one of the paramters, so it would simply be a case of checking which table is requesting data/information
You don't have to point your table views to the view controller. Your view controller could store two objects whose only purpose is to repond to table view delegate methods
Unless the tables are trivial, I think the second option is the cleanest.
Add all of your UITableViews in the UIViewController's view, set their tag properties to something you can distinct them and also set their delegates (usually self if your UIViewController implements the UITableViewDelegate protocol). Every method in the UITableViewDelegate passes UITableView reference as an argument and with the value of the tag property you can find out which table view is processed.

Resources