0

我正在使用 UIImagePickerController 将照片添加到照片和计划的应用程序目录中,父 ViewController 是 tableViewController。我在表的其他地方报告了问题,没有在dismissModalViewController上添加文件刷新,我读到dismissModalViewController不会在父控制器中触发viewWillAppear,我看到@WrightCS在这里使用NSNotificationCenter回答。但是,当我尝试它时,我得到了以下信息:

-[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

1

您的someMethodToReloadTable方法需要一个参数,因此您的选择器viewDidLoad需要一个:.

改变:

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

到:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someMethodToReloadTable:) name:@"reloadTable" object:nil];
于 2013-07-22T14:53:05.213 回答