如何从另一个类访问 ViewController 属性?
(ViewController 是由 XCode 创建的)
这是 ViewController.h 的代码:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
@interface ViewController : UIViewController{
AppDelegate *appDelegate; //il delegate disponibile per tutta la classe
int numPag; //indice array (sulle pagine html da visualizzare)
NSString *path;
NSURL *baseURL;
NSString *file;
NSString *contentFile;
}
- (IBAction)sottrai:(id)sender;
- (IBAction)aggiungi:(id)sender;
@property (strong, nonatomic) IBOutlet UILabel *valore;
@property (strong, nonatomic) IBOutlet UIWebView *web;
@end
谢谢!
[编辑]
我使用 Xcode 4.3.2 和 AppDelegate.m 的代码找不到类似的东西:
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
现在,我在方法 didFinishLaunchingWithOptions:(into AppDelegate.m) 中输入了这段代码:
viewController = [[UIViewController alloc] initWithNibName:@"ViewController" bundle:nil];
[viewController.web loadHTMLString:contentFile baseURL:baseURL];
在文件 AppDelegate.h 中添加变量 viewController:
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>{
NSArray *pageInItalian;
NSArray *pageInEnglish;
UIViewController *viewController;
}
@property (strong, nonatomic) NSArray *pageInLanguage;
@property (strong, nonatomic) UIWindow *window;
@end
我做对了吗?错误是:在“UIViewController *”类型的对象上找不到属性“web”