Ios 如何在AppDelegate方法中访问UITextField
嗨,我不知道如何从AppDelegate方法访问我的UITextField 我试图补充一点Ios 如何在AppDelegate方法中访问UITextField,ios,uitextview,appdelegate,Ios,Uitextview,Appdelegate,嗨,我不知道如何从AppDelegate方法访问我的UITextField 我试图补充一点 @implementation TestAppDelegate @synthesize textField; 但我还是犯了一个错误。我只是想知道是否可以从AppDelegate方法访问它。如果您的项目中有UIViewController类,并且您正在使用interface builder,并且您希望从AppDelegate访问UITextField,则您的项目应该如下所示: MyViewControl
@implementation TestAppDelegate
@synthesize textField;
但我还是犯了一个错误。我只是想知道是否可以从AppDelegate方法访问它。如果您的项目中有
UIViewController
类,并且您正在使用interface builder,并且您希望从AppDelegate访问UITextField
,则您的项目应该如下所示:
MyViewController.h
@interface MyViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *textField;
@end
MyAppDelegate.h
#include "MyViewController.h"
@interface MyAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
... 你会遇到什么错误?你不应该在AppDelegate中访问类似的内容。如果你努力写一个更好的问题,你可以希望得到答案并解决你的问题。
@implementation MyAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MyViewController *viewController = (MyViewController *)[_window rootViewController];
[[viewController textField] setText:@"It should work!"]
}
@end