0
votes

I am trying to reload my table view controller after inserting an item using core data. I am using storyboards to present my modal view controller and am setting the delegate of the destination view controller in prepare to segue but i believe that is the issue, as my didAddCollection method is not being triggered. I am not sure what i am missing here. i used iOS TableView Reload after dismissing modal as the base for the current code i have.

In my CCNewCollectionViewController.h

@protocol NewCollectionDelegate <NSObject>

-(void) didAddCollection;

@end


@interface CCNewCollectionViewController : UIViewController {
    id delegate;
}

@property (nonatomic, retain) id <NewCollectionDelegate> delegate;

In my CCNewCollectionViewController.m

@implementation CCNewCollectionViewController

@synthesize delegate;

// save data

[self.delegate didAddCollection];

// dismiss view controller

In my CollectionTableViewController.m

@interface CollectionTableViewController () <NSFetchedResultsControllerDelegate, NewCollectionDelegate>

-(void) didAddCollection {

    [self.tableView reloadData];

}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    [[segue destinationViewController] setDelegate:self];
}
2
I can't understand @interface CCNewCollectionViewController : UIViewController { id delegate; }.Lumialxk
CCNewCollectionViewController is the view i am presenting modally. What in particular are you having trouble understanding?werne2j
Why you have one property and one member variable both named "delegate"?Lumialxk
following the link i put in my question, which is creating the delegate instance and then defining it. But i have been tinkering with that as well. I removed the { id delegate } and nothing changed.werne2j

2 Answers

1
votes

A very silly mistake. When setting the delegate of the destination view controller, i was actually setting the delegate of the UINavigationController instead of the CCNewCollectionViewController.

UINavigationController *nc = [segue destinationViewController];
CCNewCollectionViewController *vc = nc.viewControllers[0];
[vc setDelegate:self];

I changed my prepareForSegue code to this and it solved my problems!

0
votes

Not sure if this will solve your problem, but I think it is more typical to just create a weak delegate property. No need to synthesize.

    @interface CCNewCollectionViewController : UIViewController
    @property (nonatomic,weak) id <NewCollectionDelegate> delegate;
    ...
    @end

See here for more information about working with protocols.