我已经查看了有关此事的其他主题,但无法确定我的错误。
我是 IOS 编程的新手。我正在尝试创建一个程序来查看 2 个按钮的选定状态并确定按钮的选定状态是否相同。
我目前正在尝试使用模型来确定按钮的选定状态,然后将该状态传递给标签。我有一条错误消息:
No visible @interface for 'MatchTest' declares the selector 'doesItMatch'
如果能提供任何帮助,我将不胜感激。
谢谢!
这是 MatchTest.h 文件
// MatchTest.h
#import <Foundation/Foundation.h>
@interface MatchTest : NSObject
@end
这是 MatchTest.m 文件
// MatchTest.m
#import "MatchTest.h"
@implementation MatchTest
-(NSString*)doesItMatch:(UIButton *)sender
{
NSString* tempString;
if(sender.isSelected)
{
tempString = @"selected";
}
else
{
tempString = @"not selected";
}
return tempString;
}
@end
这是 MatchViewController.h 文件
// MatchViewController.h
#import <UIKit/UIKit.h>
#import "MatchTest.h"
@interface MatchViewController : UIViewController
@end
这是 MatchViewController.m 文件
// MatchViewController.m
#import "MatchViewController.h"
@interface MatchViewController ()
@property (weak, nonatomic) IBOutlet UILabel *matchLabel;
@property (strong, nonatomic) MatchTest *match;
@end
@implementation MatchViewController
-(MatchTest *)match
{
if(!_match) _match = [[MatchTest alloc] init];
return _match;
}
- (IBAction)button:(UIButton *)sender
{
sender.selected = !sender.isSelected;
self.matchLabel.text = [self.match doesItMatch:sender];
}
@end
最佳答案
在 MatchTest.h 文件中声明 doesItMatch
方法
喜欢
在 MatchTest.h 中
-(NSString*)doesItMatch:(UIButton *)sender;
编译器无法在 .h 文件中归档 doesItMatch 方法的声明,这就是出现该错误的原因。
关于ios - 从继承类 -ios 实现方法时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18309100/