Frage

I have a UICollectionView. When the user taps on an item, a modal form sheet window appears over the view. When the user taps done, I want to call [self.collectionView reloadData], or something that does the equivalent. However, viewWillAppear does not work for the form sheet. Any idea how to get this to work?

War es hilfreich?

Lösung 3

Someone on the Apple Dev forums helped me. For reference: Put this in the CollectionView Controller. - (IBAction)formSheetWindowDoneButtonPressed:(UIStoryboardSegue *)sender { [self.collectionView reloadData]; }

You can change the name of the method, but keep the rest of the signature the same. Now, in the storyboard, control+drag from your done button to the exit segue for that view controller. That's the green box at the bottom of the view with the arrow pointing to the right. When you let go of the drag, you should see formSheetWindowDoneButtonPressed: as an option. Pick that one, and you've now linked your Exit Segue appropriately. When they press done, the method above is called and your collection view reloads.

Andere Tipps

The best way to do this is to implement method

-(void) closeModalView {
    [self dismissViewControllerAnimated:YES completion:nil];
}

in your UICollectionView. This method is better to declare in protocol that your UICollectionView should confirm to:

@protocol YourModalViewDelegate <NSObject>;

    @required
    -(void) closeModalView;

@end

call this method in modal view when you want to close itself:

[delegate closeModalView];

where delegate is a property in modal view:

@property (strong, nonatomic) id <YourModalViewDelegate> delegate;

This property might be set in UICollectionView with the following way:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"segueToModalViewIdentifier"]) {
        YourModalViewClass *yourModalView = (YourModalViewClass *)[segue destinationViewController];
        [yourModalView setDelegate:self];
}

You should create a protocol on the controller that presents the new modal view controller. Then, you can call that method when you press the done button in the second view controller. You can find a working example of how to create such a protocol in Xcode's Utility Application template. You can find additional information in Apple's programming guides.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top