xcode 如何解决错误“没有可见的@interface for 'UIViewController' 声明了选择器”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26361858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to solve the error 'No visible @interface for 'UIViewController' declares the selector ''
提问by ???
I am using Xcode 5
我正在使用 Xcode 5
This is my AppDelegate.h file
这是我的 AppDelegate.h 文件
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIViewController *viewController;
@end
This is my AppDelegate.m file
这是我的 AppDelegate.m 文件
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
[self.viewController saveData];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
[self.viewController loadData];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
This is my ViewController.h file
这是我的 ViewController.h 文件
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
//some variables declared here
@interface ViewController : UIViewController <UIActionSheetDelegate, UINavigationBarDelegate, UIImagePickerControllerDelegate>{
//some outlets declared here
}
//some actions and - (void) declared here
- (NSString *) getFilePath;
- (void) saveData;
- (void) loadData;
@end
Beside the code [self.viewController saveData]
and [self.viewController loadData]
there's an error message:'No visible @interface for 'UIViewController' declares the selector 'saveData'
and 'No visible @interface for 'UIViewController' declares the selector 'loadData'
.
What should I do?
在代码旁边[self.viewController saveData]
,[self.viewController loadData]
还有一条错误消息:'No visible @interface for 'UIViewController' declares the selector 'saveData'
和'No visible @interface for 'UIViewController' declares the selector 'loadData'
。我该怎么办?
回答by Ponf
You should specify class of UIViewController in your AppDelegate.h file:
您应该在 AppDelegate.h 文件中指定 UIViewController 的类:
@property (strong, nonatomic) ViewController *viewController;
and add import statement in this file
并在此文件中添加导入语句
#import "ViewController.h"
回答by Greg
Your viewController
is subclass of UIViewController class so there is not saveData/LoadData method.
The two method exists in your custom class - ViewController.
您viewController
是 UIViewController 类的子类,因此没有 saveData/LoadData 方法。这两种方法存在于您的自定义类 - ViewController 中。
The solution is replace line in AppDelegate.h from:
解决方案是从以下位置替换 AppDelegate.h 中的行:
@property (strong, nonatomic) UIViewController *viewController;
to:
到:
@property (strong, nonatomic) ViewController *viewController;
or cast viewController to ViewController every time you call saveData/loadData
或每次调用 saveData/loadData 时将 viewController 转换为 ViewController
回答by Phillip Mills
If the view controller in the app delegate is truly a ViewController
object, then change the property to say so:
@property (strong, nonatomic) ViewController *viewController;
如果 app 委托中的视图控制器确实是一个ViewController
对象,那么将属性更改为这样:
@property (strong, nonatomic) ViewController *viewController;
You will then also need the matching @class
(.h) and #import
(.m) statements.
然后,您还需要匹配的@class
(.h) 和#import
(.m) 语句。