首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从SourceViewController访问DetailViewController方法;两者都在NSSplitViewController (Objective-C)中

如何从SourceViewController访问DetailViewController方法;两者都在NSSplitViewController (Objective-C)中
EN

Stack Overflow用户
提问于 2020-08-18 19:48:59
回答 1查看 34关注 0票数 0

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

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

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

我在DetailViewController中有一个我试图从SourceViewController访问的实例类方法:

代码语言:javascript
复制
-(void) imageSelected: (NSString*) name{
    self.imageView.image = [NSImage imageNamed:name];
}

为了获得访问权限,我通过NSSplitViewController超类创建了一个指向DetailViewController类实例的指针。所以我爬到树上,然后再下到DetailViewController:

代码语言:javascript
复制
//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‘。

我做错了什么?我如何才能解决这个问题?

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2020-08-24 09:59:10

您可以尝试更改此设置吗:

NSViewController *imageVC = splitCV.childViewControllers1;

如下所示:

DetailViewController *imageVC = splitCV.childViewControllers1;

并查看imageVC.imageSelected(self.picturesrow)现在是否可以正确自动完成?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63467990

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档