0

I'm developing a simple app which downloads images from Dribbble, but I'm having problem reloading the data for my collection view. I have two views set up with ViewDeck, center is my main view which contains the collection view and another view contains table view with settings and from there I'm trying to call a method in the first view and reload data when item is tapped but it just doesn't work.

I tried to call the same method from the main window using button -> worked like a charm but from the second window it just doesn't update the data.

I tried to debug somehow and seems like my collection is null when the reload is called, no idea why.

SettingsViewController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSLog(@"tap");

    JKViewController *appDelegate = [[JKViewController alloc] init];
    appDelegate.dataHasChanged = YES;
    [appDelegate refresh];

    [self.viewDeckController closeLeftViewAnimated:YES];
}

MainView

- (void)refresh{

    NSLog(@"refresh");

    if(dataHasChanged)
    {
        switch (listType) {
            case 0:
                [self refreshWithList:SPListPopular];
                break;

            case 1:
                [self refreshWithList:SPListEveryone];
                break;

            case 2:
                [self refreshWithList:SPListDebuts];
                break;

            case 3:
                [self refreshWithList:SPListPopular];
                break;

            default:
                [self refreshWithList:nil];
                break;
        }

        dataHasChanged = NO;
        NSLog(@"Should refresh");
    }

    NSLog(@"%d", [self->shots count]);
    NSLog(@"Collection view: %@",self.collectionView.description);
    NSLog(@"self.list: %@",self.list);
    NSLog(@"List type: %d", listType);
}

This doesn't work :/, but when I call it from button in the MainView it works.

- (IBAction)changeList:(id)sender {
    [self refreshWithList:SPListDebuts];
}

Does anyone know what could be the issue?

Edit - Solved

Getting the right instance of the centerViewController

JKViewController *mainController = ((UINavigationController*)self.viewDeckController.centerController).visibleViewController.navigationController.viewControllers[0];
johnkodes
  • 123
  • 1
  • 13
  • You can use Dribbble iOS SDK to download shots in a single-line API call method, it could save you a lot of time. See the github repo: https://github.com/agilie/dribbble-ios-sdk – Dmitry Salnikov Jul 02 '15 at 15:20

1 Answers1

0

The reason that you are not seeing your data being updated is because you are creating a new view controller and telling that to refresh. This new view controller has been initialized but not added to your view hierarchy. What you want to do is message the existing view controller like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSLog(@"tap");

    JKViewController *mainViewController = self.viewDeckController.centerViewController;
    mainViewController.dataHasChanged = YES;
    [mainViewController refresh];

    [self.viewDeckController closeLeftViewAnimated:YES];
}

Also, please note that I have changed the variable name in my revision. Naming a UIViewController instance 'appDelegate' is very confusing.

geraldWilliam
  • 4,123
  • 1
  • 23
  • 35
  • Do you think you can help me more :)? – johnkodes Jun 20 '13 at 00:29
  • No, it was clear :), but read my another answer. I didn't know, how to place it into the comment. ViewDeck return Navigation controller but navigationController.ViewControllers shows 0 VCs...I think I have done my project too complicated or I shouldn't have used ViewDeck with Storyboards... – johnkodes Jun 20 '13 at 09:00
  • So I managed to get it working. I got the viewController using this code. `JKViewController *mainController = ((UINavigationController*)self.viewDeckController.centerController).visibleViewController.navigationController.viewControllers[0];` – johnkodes Jun 20 '13 at 09:26
  • Sorry I missed your comments last night. It was late here. If my answer was helpful, an accept is always appreciated. – geraldWilliam Jun 20 '13 at 16:52