我有一个 UICollectionView。当用户点击一个项目时,一个模态表单窗口会出现在 View 上方。当用户点击完成时,我想调用 [self.collectionView reloadData]
,或执行等效的操作。但是,viewWillAppear
不适用于表单。知道如何让它发挥作用吗?
最佳答案
最好的方法是实现方法
-(void) closeModalView {
[self dismissViewControllerAnimated:YES completion:nil];
}
在你的 UICollectionView 中。此方法最好在协议(protocol)中声明您的 UICollectionView 应确认:
@protocol YourModalViewDelegate <NSObject>;
@required
-(void) closeModalView;
@end
当你想关闭自身时,在模态视图中调用这个方法:
[delegate closeModalView];
其中 delegate 是模态视图中的一个属性:
@property (strong, nonatomic) id <YourModalViewDelegate> delegate;
可以通过以下方式在 UICollectionView 中设置此属性:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"segueToModalViewIdentifier"]) {
YourModalViewClass *yourModalView = (YourModalViewClass *)[segue destinationViewController];
[yourModalView setDelegate:self];
}
关于ios - 完成模态视图后重新加载 UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21790070/