Trong ứng dụng iOS của tôi, người dùng có thể chọn một hình ảnh từ danh sách, khi họ được trình bày với một phương thức có chứa hình ảnh và các tùy chọn để xóa hình ảnh. Nếu người dùng chọn xóa hình ảnh, cô ấy được trả về chế độ xem ban đầuController chứa danh sách hình ảnh. Tôi cần phải làm mới ViewController ban đầu để xem xét hình ảnh đã xóa.Làm mới Parent ViewController sau khi loại bỏ ModalViewController
Tôi đã thử sử dụng NSNotificationCenter để phát khi hình ảnh bị xóa sang Bộ điều khiển chế độ xem gốc. Tuy nhiên, có vẻ như chương trình phát sóng chưa bao giờ được nhận.
Có một số cách khác để
- gửi dữ liệu trở lại cho phụ huynh ViewController sau khi phương thức được bác bỏ, và
- phát hiện khi các phương thức đó bị cách chức mẹ ViewController?
(Tôi cố gắng làm theo tấm gương nêu here, nhưng nó dường như không làm việc)
Dưới đây là mã của tôi:
EditStepViewController (gốc View Controller):
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
MediaPreviewViewController *mediaPreviewVC = (MediaPreviewViewController *)[storyboard instantiateViewControllerWithIdentifier:@"MediaPreviewViewController"];
mediaPreviewVC.selectedImageURL = [NSString stringWithFormat:@"%@",gestureRecognizer.view.tag];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mediaPreviewVC];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didDismissMediaPreview)
name:@"MediaPreviewDismissed"
object:nil];
[self presentViewController:navigationController animated:YES completion:nil];
MediaPreviewViewController (Chế độ xem thứ hai):
...
[self deleteImage];
[[NSNotificationCenter defaultCenter] postNotificationName:@"MediaPreviewDismissed" object:nil userInfo:nil];
[self dismissViewControllerAnimated:YES completion:^(){
NSLog(@"dismissed controller");
}];
Sau đó, trở lại trong EditStepViewController:
-(void)didDismissMediaPreview{
NSLog(@"dismissed media preview"); // this is never logged!
[self.view setNeedsDisplay]; // refresh view to account for deleted image
}
Cảm ơn trước sự giúp đỡ của bạn!
bạn có thể chỉ cho tôi nơi mà bạn đã thêm các quan sát viên trong editStepViewController bạn –