【问题标题】:Objective-c error with subclass not finding superclass interface子类找不到超类接口的Objective-c错误
【发布时间】:2016-11-03 07:10:24
【问题描述】:

我一直在开发一个使用集合视图的应用程序,并且我正在创建一个自定义视图单元格(类别视图单元格),它是 UICollectionViewCell 的子类。我还想创建自定义视图单元(LinkCell)的子类。我已经搜索了一段时间,但找不到为什么会出现错误“找不到 'CategoryViewCell' 的接口声明,'LinkCell' 的超类”

//CategoryViewCell.h
#import <UIKit/UIKit.h>
#import "ViewController.h"

@class ViewController;

@interface CategoryViewCell : UICollectionViewCell

@property (weak, nonatomic) IBOutlet UIImageView *image;

@property (nonatomic) ViewController *parentView;
@property (nonatomic) NSString *cellName;

@end
//CategoryViewCell.m
#import "CategoryViewCell.h"

@implementation CategoryViewCell

@end

//LinkCell.h
#import <UIKit/UIKit.h>
#import "CategoryViewCell.h"
#import "PJP Webview.h"

@interface LinkCell : CategoryViewCell //Error here

@property (nonatomic) NSString *username;
@property (nonatomic) NSString *password;
@property (nonatomic) NSString *urlToLink;
@property (nonatomic) NSString *urlToLinkS;
@property (nonatomic) NSString *urlToLinkP;
@property (nonatomic) NSString *urlToLinkT;
@property (nonatomic) NSString *body;

-(IBAction)celltapped:(id)sender;

@end
//LinkCell.m
#import "LinkCell.h"

@implementation LinkCell

@synthesize urlToLink, username, password, image, cellName, parentView;

-(IBAction)celltapped:(id)sender {

    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *launchString = [NSString stringWithFormat:@"hasLaunched%@Before", self.cellName];
    BOOL hasLaunchedCellBefore = [userDefaults boolForKey:launchString];
    if (!hasLaunchedCellBefore) {
        // first time launch code

        hasLaunchedCellBefore = TRUE;
        [userDefaults setBool:hasLaunchedCellBefore forKey:launchString];
        [userDefaults synchronize];

        PJP_Webview *vc = [parentView.storyboard instantiateViewControllerWithIdentifier:@"vc"];
        vc.currentCell = self;
        [parentView presentViewController:vc animated:YES completion:nil];
    }
    else {

    }
}

@end

谁能告诉我我的错误在哪里?

【问题讨论】:

  • 您是否尝试过清理项目文件夹(cmd+shift+k)?然后再次构建。
  • @Joshua,是的,我有,当我清理它时,错误消失了,但是一旦我构建它,错误就会回来

标签: ios objective-c inheritance subclass superclass


【解决方案1】:

我刚刚解决了; ViewController.h 使用 CategoryViewCell,我导入了 .h 并将 @class 用于 CategoryViewCell.h 上的 ViewController 属性。只有@class 是必需的;我猜想创建了某种循环依赖。奇怪的是 CategoryViewCell.h 没有错误,它的子类有。感谢所有回答的人!

【讨论】:

    【解决方案2】:

    选择文件 CategoryViewCell.m 并检查它是否已添加到目标。

    【讨论】:

    • 头文件未添加到目标中。
    • @Proton,抱歉延迟回复。 CategoryViewCell.m 确实具有选择项目目标的目标成员资格。但是还是不行。
    • 我刚刚解决了; ViewController.h 使用 categoryviewcell,我导入了 .h 并将 @class 用于 ViewController 属性。只有类是必需的。
    猜你喜欢
    • 1970-01-01
    • 2012-05-26
    • 1970-01-01
    • 1970-01-01
    • 2012-05-13
    • 1970-01-01
    • 2018-04-03
    • 1970-01-01
    • 2011-11-27
    相关资源
    最近更新 更多