如何解决如何从SourceViewController访问DetailViewController方法;都在NSSplitViewControllerObjective-C中
我是Objective-C的新手,觉得学习很重要。我给自己以下挑战:
我有一个NSSplitViewController设置,每个视图有两个类; (i)SourceViewController:NSViewController和(ii)DetailViewController:NSViewController。
通过选择SourceViewController的NSTableView行,我想在SourceViewController内的ImageView中更改图像
我正在尝试从SourceViewController访问的DetailViewController中有一个实例类方法:
-(void) imageSelected: (NSString*) name{
self.imageView.image = [NSImage imageNamed:name];
}
为了获得访问权限,我通过NSSplitViewController超类创建了一个指向DetailViewController类实例的指针。因此,我在树上向上再向下到DetailViewController:
//gets the row number that was selected
-(void) tableViewSelectionDidChange:(NSNotification *)notification{
NSLog(@"%ld",[[notification object] selectedRow]);
NSInteger row = [[notification object] selectedRow];
//get access to the parent view controller
//NSSplitViewController *splitCV = self.parentViewController;
NSSplitViewController *splitCV = ((NSSplitViewController *)self.parentViewController);
NSViewController *imageVC = splitCV.childViewControllers[1];
NSLog(@"%@",imageVC.className); //detail view controller
//***** HERE'S THE PROBLEM******
imageVC.imageSelected(self.pictures[row]); //<- imageSelect isn't recognised
}
但是,这不起作用,因为自动完成功能无法识别imageVC指向的功能。打印imageVC.className输出,显示名称为'DetailViewController'。
我在做什么错,我该如何解决?
预先感谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。