Roman Barzyczak
Roman Barzyczak

Reputation: 3813

Superclass for UITableViewController and UIViewController

Is any ViewController which is super class for UITableViewController and UIViewController ? Because I need it for not copy my business logic.

Upvotes: 3

Views: 3422

Answers (5)

Julian B.
Julian B.

Reputation: 3725

i'm currently attempting to accomplish the same (create a superclass to place custom logic for all my VCs to execute). in my particular scenario, i want to track screen views using google analytics' API, which should be called in viewWillAppear. this would require me to place whatever code is required within that method for every view controller.

but i found this gem: method sizzling. thanks to mr. mattt thompson for that!

if you read closely, you will find that you will be able to create a category in which you have the power to replace the existing implementation of a given selector.

however as pointed out by @duncan d, if you seek to just extend behavior, you can simply create a regular category.

Upvotes: 2

rambo
rambo

Reputation: 61

NSObject is a father of most of the classes .. you need to provide datasource and delegate class to implement the table view controller ..

Upvotes: 0

Duncan C
Duncan C

Reputation: 131426

As the other commenter said, UITableViewController is a fairly thin API on top of a UIViewController. You might be able to start from UIViewController and add the required logic to manage your table view to your custom class. However, there are some things that UITableViewController supports, like static table views and cell prototypes, that would be difficult or impossible to support if you did not use a UITableViewController.

Another alternative would be to create a category of UIViewController and add your extra methods to the category. Category methods are available to the class they are added to and all subclasses, almost as if you added the methods to the base class.

There are a couple of restrictions to category methods however.

  • You can't override methods from the base class, only add new methods.
  • You can't add instance variables in a category.

Upvotes: 2

Jyothi
Jyothi

Reputation: 384

Create an NSObject class and write all your Business Logic there and make it as Singletone and call this class where ever you want

Upvotes: -1

Suhit Patil
Suhit Patil

Reputation: 12023

Use MVC pattern in your application and you can create a Model for storing your business logic and it can communicate with your view through ViewController object.

Upvotes: 0

Related Questions