我正在使用UIImagePickerController将照片添加到照片和计划的应用目录中,其中父ViewController是一个tableViewController。我在表的其他地方报告的问题没有使用dismissModalViewController上添加的文件刷新,并且我已经读过dismissModalViewController不会在父控制器中触发viewWillAppear,我看到@WrightCS使用NSNotificationCenter {{3}回答}。但是,当我尝试它时,我得到了以下内容:
- [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];
}
答案 0 :(得分: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];