我有一个用于我的应用程序的自定义数据控制器,并且在其中我设置了一些委托方法。它们都可以工作,但在我想要它们的时候却不行。当我调用 [dataController refreshData] 时,我有一个委托方法 refreshDidStart 和 refreshDidFinishWithoutError。我分配数据控制器,将委托设置为 self 并在 applicationDidFinishLaunching 中调用 refreshData,但是当方法执行完成时,委托方法不会刷新视图控制器中的表视图。但是,当我设置刷新 UIBarButtonItem 来调用 [dataController refreshData] 时,会调用 refreshDidFinish 委托方法并执行预期的操作。我相信这与我正在使用的拆分视图控制器有关。下面是代码:
应用代表:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
dataController = [[DataController alloc] init];
[dataController setDelegate:self];
[dataController refreshData];
}
主视图控制器:
- (void)viewDidLoad
{
[super viewDidLoad];
dataController = [[DataController alloc] init];
[dataController setDelegate:self];
self.tableView.backgroundView = nil;
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"texture3.png"]];
}
- (void)refreshDataDidStart:(DataController *)view {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText = @"Loading";
}
- (void)refreshDataDidFinishWithoutError:(DataController *)view {
[callsTableView reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
- (void)refreshDataDidFailWithError:(DataController *)view withError:(NSError *)error {
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSLog(@"%@", error.localizedDescription);
}