I have a problem with my tableview.
It has a space on top like this:
When I open the TasksTableViewController, the problem doesn't show. But when I open another viewcontroller from TaskTableVC like this:
FilterTasksTableViewController * fttvc = [self.storyboard instantiateViewControllerWithIdentifier:@"FilterTasksTableViewController"];
fttvc.delegate = self;
UINavigationController * navVC = [self.storyboard instantiateViewControllerWithIdentifier:@"PopoverNavigationController"];
[navVC setViewControllers:@[fttvc]];
[self presentViewController:navVC animated:YES completion:nil];
and go back to TaskTableVC, the problem occurs. When I "pull down to refesh", it goes back to normal.
in my code for TaskTableVC:
- (void)viewWillAppear:(BOOL)animated {
//other code
[self populate];
}
- (void)viewDidLoad {
dispatch_async(dispatch_get_main_queue(), ^{
self.refreshControl = [[UIRefreshControl alloc] init];
self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@" "];
[self.refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
[self setRefreshControl:self.refreshControl];
});
[self populate];
}
- (void)populate {
TaskHandler *handler = [[TaskHandler alloc] initWithContext:_context];
NSArray *allTasks = [handler getAll];
_tasks = [self filterTasks:allTasks];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"startDate" ascending:NO];
NSArray *descriptors = [NSArray arrayWithObjects:descriptor, nil];
_tasks = [[NSMutableArray alloc] initWithArray:[_tasks sortedArrayUsingDescriptors:descriptors]];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
[self.refreshControl endRefreshing];
});
}
I hope you can help me with this weird problem.
I solved my problem with the code.
I thought there was something wrong with the Refresh control
so I moved it out of the dispatch_aysnc(dispatch_get_main_queue()
and added [self.tableview reloadData
. That fixed my problem. Thanks everyone for answering. :)