如何从SourceViewController访问DetailViewController方法;都在NSSplitViewControllerObjective-C中

问题描述

我是Objective-C的新手,觉得学习很重要。我给自己以下挑战:

我有一个NSSplitViewController设置,每个视图有两个类; (i)SourceViewController:NSViewController和(ii)DetailViewController:NSViewController。

通过选择SourceViewController的NSTableView行,我想在SourceViewController内的ImageView中更改图像

enter image description here

我正在尝试从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 (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...