ios - 从继承类 -ios 实现方法时遇到问题

标签 ios class methods model call

我已经查看了有关此事的其他主题,但无法确定我的错误。

我是 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/

相关文章:

ios - 在 WKWebView 中使用自定义字体

iphone - 从自定义 UITableViewCell 中的 UITextFields 中检索值

ios - 如何在屏幕关闭时检测 iOS 应用程序中的 iBeacon?

将方法作为回调传递的 javascript 问题

iphone - 如何调用采用可变数量参数的方法的父类(super class)实现,如 [UIAlertView initWithTitle ...]?

java | key 扣店练习| main 中的钥匙串(keychain)编号变量不想存储

ios - AudioUnitSetProperty Swift 错误

c++ - 如何在子类的 vector 上应用多态函数

delphi - 为什么在通过元类类工厂实例化时不调用派生构造函数?

c++ - 如何在类的私有(private)部分定义二维结构数组?