Objective-c 子类找不到超类接口时出错
Objective-c error with subclass not finding superclass interface
我一直在开发一个使用集合视图的应用程序,我正在创建一个自定义视图单元格(类别视图单元格),它是 UICollectionViewCell 的一个子类。我还想创建自定义视图单元 (LinkCell) 的子类。我已经搜索了一段时间,但找不到我收到错误 "Cannot find interface declaration of 'CategoryViewCell', superclass of '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
谁能告诉我我的错误在哪里?
选择文件 CategoryViewCell.m 并检查它是否已添加到目标。
我刚刚解决了; ViewController.h 使用 CategoryViewCell,我导入了 .h 并将 @class 用于 CategoryViewCell.h 上的 ViewController 属性。只有 @class 是必需的;我想创建了某种循环依赖。奇怪的是 CategoryViewCell.h 没有错误,它的 subclass 有错误。感谢所有回答的人!
我一直在开发一个使用集合视图的应用程序,我正在创建一个自定义视图单元格(类别视图单元格),它是 UICollectionViewCell 的一个子类。我还想创建自定义视图单元 (LinkCell) 的子类。我已经搜索了一段时间,但找不到我收到错误 "Cannot find interface declaration of 'CategoryViewCell', superclass of '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
谁能告诉我我的错误在哪里?
选择文件 CategoryViewCell.m 并检查它是否已添加到目标。
我刚刚解决了; ViewController.h 使用 CategoryViewCell,我导入了 .h 并将 @class 用于 CategoryViewCell.h 上的 ViewController 属性。只有 @class 是必需的;我想创建了某种循环依赖。奇怪的是 CategoryViewCell.h 没有错误,它的 subclass 有错误。感谢所有回答的人!