我是Objective-C的新手,觉得学习很重要。我给了自己以下挑战:
我有一个NSSplitViewController设置,每个视图有两个类;(i) SourceViewController: NSViewController和(ii) DetailViewController: NSViewController。
通过选择SourceViewController的NSTableView行,我希望在SourceViewController中更改ImageView中的图像

我在DetailViewController中有一个我试图从SourceViewController访问的实例类方法:
-(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
}然而,这不起作用,因为autocomplete不能识别imageVC指向的函数。打印imageVC.className输出,显示名称为'DetailViewController‘。
我做错了什么?我如何才能解决这个问题?
提前感谢
发布于 2020-08-24 09:59:10
您可以尝试更改此设置吗:
NSViewController *imageVC = splitCV.childViewControllers1;
如下所示:
DetailViewController *imageVC = splitCV.childViewControllers1;
并查看imageVC.imageSelected(self.picturesrow)现在是否可以正确自动完成?
https://stackoverflow.com/questions/63467990
复制相似问题