Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在AppDelegate方法中访问UITextField_Ios_Uitextview_Appdelegate - Fatal编程技术网

Ios 如何在AppDelegate方法中访问UITextField

Ios 如何在AppDelegate方法中访问UITextField,ios,uitextview,appdelegate,Ios,Uitextview,Appdelegate,嗨,我不知道如何从AppDelegate方法访问我的UITextField 我试图补充一点 @implementation TestAppDelegate @synthesize textField; 但我还是犯了一个错误。我只是想知道是否可以从AppDelegate方法访问它。如果您的项目中有UIViewController类,并且您正在使用interface builder,并且您希望从AppDelegate访问UITextField,则您的项目应该如下所示: MyViewControl

嗨,我不知道如何从AppDelegate方法访问我的UITextField

我试图补充一点

@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