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