我无法将故事板中的表视图的数据源和委托出口连接到我的自定义委派类。我想将这些表函数委托给另一个类。有些事情我从根本上被误解为有关代表团,网点和故事板中的东西。UITableView数据源和委托将不会连接到自定义类
背景
我有一个UIViewController
具有含有UIPickerView
的图,除其他事项外,一个UITableView
。
我已经达到了我的UIViewController
太大的程度,我想将与表格有关的函数移动到另一个类中。
我创建了以下类来包含那些表方法,如numberOfSectionsInTableView:
。
@interface ExerciseTableDelegate : NSObject <UITableViewDelegate, UITableViewDataSource>
@property (strong, nonatomic) ExerciseDataController *dataController;
@end
我想过把一个参考类以上我UIViewController
@interface ExerciseViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>
{
UIPickerView *exercisePicker;
}
@property (strong, nonatomic) IBOutlet ExerciseTableDelegate *tableDelegate;
@end
我希望故事板内,当我拖我的表的数据源或委托出口的一个查看到UITableViewController
它会给我连接到我的委托类的能力。它没有。
然后我尝试在故事板内创建一个对象,并给它类ExerciseTableDelegate
。然后,我可以将表视图委托拖动到该对象,但这不是我在AppDelegate
中设置的同一个对象。
我的应用程序委托
- (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;
// Override point for customization after application launch.
return YES;
}
- 我需要让我的对象独立的,并仍在初始化它 委托?
- 我是否需要在代码中执行此设置,而不是在 情节提要中进行设置?
- 在故事板中创建对象是错误的想法?
我觉得我很接近,但我觉得我做得太多了。
Thankyou @jrturton。那就是诀窍。除此之外,我需要做标准的事情来为ExerciseViewControllers tableView创建一个IBOutlet,并且需要将它连接到故事板。 – AllTheThingsICanDo