Ami*_*gin 18 delegates types objective-c navigator
我对目标c很新,并且有一些基本问题.
我使用导航器编写了一个简单的程序,一切正常.然后我添加了几行代码(甚至不记得究竟是什么,似乎与问题无关)并且问题发生了.我试过ctrl + z,问题仍然存在:
我运行程序并得到这些错误:
1. unknown type name "mainController"
2. property with 'retain (or strong)' attribute must be of object type
Run Code Online (Sandbox Code Playgroud)
而mainController是第一个要加载的屏幕.
这是appDelegate.h文件:
#import <UIKit/UIKit.h>
#import "mainController.h"
#import "WishesList.h"
#import "Wish.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) IBOutlet UINavigationController *navController;
@property (strong, nonatomic) IBOutlet mainController *viewController; // this line creates the errors
@property (strong, nonatomic) WishesList *WishesArray;
@property (strong, nonatomic) NSIndexPath *temp;
@end
Run Code Online (Sandbox Code Playgroud)
这是appDelegate.m文件的相关部分:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
WishesArray = [[WishesList alloc]init];
temp = nil;
[self setViewController:[[mainController alloc]init]];
[self setNavController:[[UINavigationController alloc]initWithRootViewController:self.viewController]];
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
这是mainController.h:
#import <UIKit/UIKit.h>
#import "addWishController.h"
#import "displayWish.h"
#import "WishesList.h"
#import "Wish.h"
@interface mainController : UIViewController
@property (nonatomic, weak) WishesList *list;
@property (nonatomic, strong) IBOutlet UITableView *wishTable;
- (void)addWish;
@end
Run Code Online (Sandbox Code Playgroud)
它已经有效......
你能弄清楚吗?
谢谢
小智 35
我想,如果你有一个导入周期,就会出现同样的错误:
Class_A.h: #import "Class_B.h"
Class_B.h: #import "Class_A.h"
要解决此问题:查找违规类的任何导入(错误选项卡是您的朋友,请为导入列表展开相关错误).删除#import
的相应
Joã*_*nes 17
这个问题发生在我身上一次.
我在我的h文件和我的APPDelegate.h中导入了"APPDelegate.h"我也在导入文件(这不应该是一个问题,但......)
我做了什么:我将导入从我自己的.h更改为.m并且它有效:)
正如其他人提到的,这确实是周期性进口造成的。要解决此问题,请删除其中一个类中的导入。但有时这还不够。如果这些类相互依赖,只需在另一个类中前向声明一个类即可:
A类:
#import <UIKit/UIKit.h>
@class B; //<- this is essential here
@interface A: NSObject
@property(nonatomic, strong) B *b;
//...
Run Code Online (Sandbox Code Playgroud)
在 B 类中,我们有:
#import "A.h"
@interface B: NSObject
@property(nonatomic, strong) A *a;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
27591 次 |
最近记录: |