UITableView inside UIViewController using Parse PFQueryTableViewController - ios

I need to create a UIViewController which has a UITableView inside it. I found some similar questions on here but I want to use a separate class a my data source and delegate, a class that will subclass PFQueryTableViewController from Parse SDK.
So in my storyboard I have one UIViewController with one UITableView on it.
I also have a class called ArticleTableViewController (inherits from PFQueryTableViewController). I would like this class to be the delegate and the datasource for my table view, but I donĀ“t know how to connect them correctly.
Any ideas?

I tried to do something like this, i've got the answer: you can't use the PFQuaryTableViewController as a subclass of a UIViewController.
Here's my original question with the answer and some useful suggestions.

Related

Add attributes for UITableViewController

I'm developing a custom class.
The goal is user will add a UITableViewController to the storyboard and set its class to mine.
and my class will fill the tableView.
Here's my question: I want to give the user to set some attributes like header color, etc in storyboard, but #IBdesignable can't be used for UITableViewController
Any idea?
I think the easiest solution is to subclass a UITableView instead of UITableViewController.

How to link Table dataSource and delegate outlets to UITableViewController?

I'm new to Swift/iOS development.
I have a UITableView in my storyboard that I want to populate with some data. In my attempt to do so, I created a class that inherits from UITableViewController. The implementation is not yet complete, but my understanding is that by inheriting from this class I can provide an IBOutlet to both dataSource and delegate.
When I try to drag the outlet into the source file, I don't get the insertion point that I got when I tested this before. See image below:
What do I have to do to define this class as the handler for the UITableView?
Set your viewController to inherit from UIViewController, not from UITableViewController (It seems like your IB is set up like that).
Do not forget to set your class to ZeroconfTableController on the interface builder.
Than, you will be able to set the delegate and datasource. NOTE: the delegate and the datasource will not create IBOutlets.
Assign the delegate and the dataSource the following way:
Also make sure, your viewController conforms to the protocols.
class ZeroconfTableController: UIViewController, UITableViewDataSource, UITableViewDelegate {
In your storyboard, select the UITableView and change this to the name of your UITableViewController subclass. You then do not need to do any linking stuff.
If you're using your own UITableView, inherit from UIViewController, not UITableViewController.
If however, you want to use a UITableViewController (which personally I don't use) in your storyboard, then do inherit from UITableViewController. In this case you won't have to wire up the UITableViewDataSource nor the UITableViewDelegate.

What does one gain from using a UITableViewController?

Why not use a UIViewController with a TableView embedded in it?
UITableViewController has three properties:
tableView;
clearsSelectionOnViewWillAppear;
refreshControl.
Also, you can create Static Cells in Interface Builder only in UITableViewController.
If you need anything from above - use it instead of UIViewController subclass.
UITableViewController is a "shortcut" that is useful in situations when you need a simple table with static data, archived in a NIB/Storyboard. Using UITableViewController lets you get most of the behavior for free, without the need to write and manage a special data source for it.
Other than that situation, UITableViewController gives you very little on top of UIViewController with an embedded UITableView.

Custom UITableViewController issue

So I created a subclass of UITableViewController and have the xib,h,m files for this controller. but when I add a UIView or a UITableViewController to my main.storyboard it will not let me set my new subclass as the custom class.
Ive been trying to get this working for about 3 days now, watching youtube videos, reading tutorials and I can't seem to find anything similar to what Im trying to do.
Im trying to create a table with header and search bar that has everything self contained, including datasets.
Make sure your class is a subclass of UITableViewController When you set it as the custom class of an UITableViewController object in the storyboard.
1: MySubClassOfTableViewController is a subclass of UITableViewController
2: Find the UITableViewController object in the storyboard
3: Set Custom Class of the UITableViewController object to MySubClassOfTableViewController

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.

Resources