I cannot connect the data source and delegate the output of the table view in the storyboard to my custom delegated class. I would like to delegate these table functions to another class. There is something that I fundamentally misunderstood regarding delegation, exits, and posting things in a storyboard.
Background
I have a UIViewController
that has a view containing a UIPickerView
and, among other things, a UITableView
.
I have reached the point where my UIViewController
too large, and I would like to move the table related functions to another class.
I created the following class containing table methods such as numberOfSectionsInTableView:
@interface ExerciseTableDelegate : NSObject <UITableViewDelegate, UITableViewDataSource> @property (strong, nonatomic) ExerciseDataController *dataController; @end
I thought to put a link to the class above in my UIViewController
@interface ExerciseViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate> { UIPickerView *exercisePicker; } @property (strong, nonatomic) IBOutlet ExerciseTableDelegate *tableDelegate; @end
I was hoping that in the storyboard, when I drag one of the data sources or delegates of my table view onto the UITableViewController
, it will give me the ability to connect to my delegated class. This is not true.
Then I tried to create an object in the storyboard by providing it with the ExerciseTableDelegate
class. Then I could drag the table view delegate into the object, but this is not the object that I configure in my AppDelegate
.
My application delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; ExerciseViewController *rootViewController = (ExerciseViewController *)[[navigationController viewControllers] objectAtIndex:0]; ExerciseTableDelegate *tableDelegate = [[ExerciseTableDelegate alloc]init]; ExerciseDataController *dataController = [[ExerciseDataController alloc] init]; tableDelegate.dataController = dataController; rootViewController.tableDelegate = tableDelegate;
- Should I make my object single and still initialize it to a delegate?
- Do I need to make this setting in code, and not in the Storyboard?
- Does the object in the storyboard create the wrong idea?
I feel like I'm close, but I think I'm doing too much.