0

UIImagePickerController を使用して、写真とプランのアプリ ディレクトリに写真を追加しています。親 ViewController は tableViewController です。テーブルの他の場所で、dismissModalViewController に追加されたファイルが更新されないという問題が報告されました。また、dismissModalViewController が親コントローラーで viewWillAppear をトリガーしないことを読み、NSNotificationCenter hereを使用して@WrightCS の回答を見ました。しかし、試してみると、次の結果が得られました。

-[MapTableViewController someMethodToReloadTable]: 認識されないセレクターがインスタンス 0x1d5ca330 に送信されました

私が使用したコードは次のとおりです。

- (void)viewDidLoad
{

    AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    self.mapPath = delegate.mapPath;

    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someMethodToReloadTable) name:@"reloadTable" object:nil];

.........

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    image=[info objectForKey:UIImagePickerControllerOriginalImage];
    pageSize = image.size;
    CGRect imageBoundsRect = CGRectMake(0, 0, pageSize.width, pageSize.height);
     NSString *path = [self.mapPath stringByAppendingPathComponent: @"image.pdf"];


    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    [self generatePdfWithFilePath:path];

    [self dismissModalViewControllerAnimated:YES];
    NSLog(@"dismiss  triggered");
    [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadTable" object:self];
    NSLog(@"notification fired");



}

- (void)someMethodToReloadTable:(NSNotification *)notification
{ NSLog(@"notification  triggered");
    [self.tableView reloadData];
}

-(void)viewDidUnload
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"reloadTable" object:nil];
}
4

1 に答える 1