objective-c - 编译时出错 : No visible @interface declares the selector

标签 objective-c uiviewcontroller interface visibility

在一节课中,我有以下内容 AlertEditorContainerViewController.m

    #import "AlertEditorContainerViewController.h"

    @interface AlertEditorContainerViewController ()
    -(void)swapViewControllers;
    @end

    @implementation AlertEditorContainerViewController

    @synthesize currentSegueIdentifier;
    @synthesize segIndex;

   - (void)swapViewControllers
   {
       self.currentSegueIdentifier = ([self.currentSegueIdentifier  isEqual: SegueIdentifierFirst]) ? SegueIdentifierSecond : SegueIdentifierFirst;
       [self performSegueWithIdentifier:self.currentSegueIdentifier sender:nil];
   }
    @end

在另一个类中我尝试调用它 AlertEditorViewController.h

    @interface AlertEditorViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
    { 
          AlertEditorContainerViewController              *containerViewController;

     }

AlertEditorViewController.h #import "AlertEditorViewController.h"

    @implementation AlertEditorViewController
    - (IBAction)segmentSwitchValueChanged:(id)sender
    {
          [containerViewController swapViewControllers];    
    }
    @end

这给出了错误“AlertEditorContainerViewController 没有可见的@interface 声明了选择器 swapViewControllers”

我已经查看了所有其他类似的查询,它们似乎都指向我在代码中找不到的拼写错误等。

最佳答案

在您的 AlertEditorContainerViewController.h 文件中声明 -(void)swapViewControllers,而不是您的 .m 文件。

有关此问题的信息,您需要查看 this Stack Overflow question ,但简而言之,通过在位于 .m 文件中的 @interface block 中声明该方法,您可以有效地将其设为私有(private)方法(其他实现文件无法访问) ).来自链接:

The interface section in the implementation file allows you to declare variables, properties, and methods that are private, meaning that they won't be seen by other classes.

编译器知道它在该特定文件的范围内,但其他文件无法访问甚至看不到该方法已定义。

关于objective-c - 编译时出错 : No visible @interface declares the selector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25001044/

相关文章:

java - 实现相同接口(interface)的多个类的相同方法

ios - 将数据传递给另一个 View Controller 不起作用

ios - 在 tableView Cell 问题中搜索

iphone - 开始点击 UIButton,但在主视图中使用 touchesEnded

ios - 从指定点呈现模态 Controller

ios - 自定义 Viewcontroller 转换未正确调整大小

java - 显式调用 Runnable.run

c# - 通过使用接口(interface)为类提供属性

iphone - iOS静态库的向后兼容性

ios - 为什么UIViewController中有一个navigationItem?