如何从另一个类访问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:(进入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 *”
我怎么走的ViewController的实例?视图控制器是由代码中的XCode创建的。我可以实例化它吗? – Antilope
看看我的编辑。 –
我还添加了编辑 – Antilope