Question: As I am new to implementing functions etc beside the basic stuff I am stuck at the moment.
I have a function with a few vars that I want to reuse in another function. Error I get is bigsrc is undefined in the second function. Clearly I am doing something wrong but I cant figure out what it is.

```
$(".villa div a").click(function(){
        var smallsrc = $(this).parent().parent().find(".blueprint a img").attr("src").replace('.jpg', '_small.jpg');    
        var bigsrc = $(this).find("img").attr("src");
        var bigsrc = bigsrc.replace('.jpg', '_big.jpg');
        var villaNaam = $(this).parent().parent().find("h2").text();
        if (bigsrc.indexOf("blueprint") != -1) {
            var smallsrc = $(this).parent().parent().find(".foto a img").attr("src");
        }
        else {
            var smallsrc = $(this).parent().parent().find(".blueprint a img").attr("src");
        }
        var smallsrc = smallsrc.replace('.jpg', '_small.jpg');

         $("#popup-img").fadeIn();
         $("#popup-bg").fadeIn();
         $("#popup-img #titel").append(villaNaam)
         $("#popup-img #big").attr("src", bigsrc);
         $("#popup-img #small").attr("src", smallsrc);
    })
    $("#small-link").click(function(){
            if (bigsrc.indexOf("blueprint") != -1) {
                var smallsrc = smallsrc.replace('blueprint', 'huis');
                var bigsrc = smallsrc.replace('huis', 'blueprint');
            }
            else {
                var smallsrc = smallsrc.replace('huis', 'blueprint');
                var bigsrc = smallsrc.replace('blueprint', 'huis');
            }
     });

```

Answer: 
I tested this out and found it working. Here is what should be done -

1) In MainPageController, create a IBOutlet property tableView and hook it up with MainPageController xib.

2) In MainPageController, create instance of CustomTableViewController in viewDidLoad and set the datasource as CustomTableViewController instance -

```
self.myCustomTableTableViewController = [[CustomTableViewController alloc] init];
self.tableView.dataSource = self.myCustomTableTableViewController;

```

This should be enough to achieved what you have described.

MainPageController.h

```
    #import <UIKit/UIKit.h>

    @interface MainPageController : UIViewController

     @property (strong, nonatomic) IBOutlet UITableView *tableView;

   @end

```

MainPageController.m

```
   #import "MainPageController.h"
   #import "CustomTableViewController.h"
   @interface ViewController ()
   @property (strong, nonatomic) CustomTableViewController *customTableViewController;

   @end

   @implementation MainPageController

   - (void)viewDidLoad
   {
       [super viewDidLoad];
       // Do any additional setup after loading the view, typically from a nib.
       self.customTableViewController = [[CustomTableViewController alloc] init];
       self.tableView.dataSource = self.customTableViewController;
   }
   @end

```
UITableViewController's \_tableView is inherent. Even if you create a new class with a xib you'll notice that the whole view is a tableview. When you drag a UITableView into a controller in your xib file or on storyboard, you are only creating a custom UITableView, and you're not going to be able to tell it to respond to another controller. The easiest pattern I can think of right now is this:

1. CustomTableViewController should subclass UIViewController. Define all your datasource functions inside it. Don't use a xib.
2. Because it is a UIViewController you can add an IBOutlet for a tableView. When you create the sublass of MainPageController, make it a subclass of CustomTableViewController, and set the tableView outlet.
3. In IB, set the datasource and delegate of the UITableView inside your ViewController to the class. It should conform since it is a subclass of CustomTableViewController.