【问题标题】:Error when compiling: No visible @interface declares the selector编译时出错:没有可见的@interface 声明选择器
【发布时间】:2014-09-19 23:35:32
【问题描述】:

在一堂课中,我有以下内容 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”

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

【问题讨论】:

    标签: objective-c uiviewcontroller interface visibility


    【解决方案1】:

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

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

    实现文件中的接口部分允许您声明私有的变量、属性和方法,这意味着它们不会被其他类看到。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多