-3
嗨,我不知道如何從AppDelegate方法訪問我的UITextField。如何訪問AppDelegate方法中的UITextField
我已嘗試添加
@implementation TestAppDelegate
@synthesize textField;
但我仍然得到一個錯誤。我只想知道是否可以從AppDelegate方法訪問它。
嗨,我不知道如何從AppDelegate方法訪問我的UITextField。如何訪問AppDelegate方法中的UITextField
我已嘗試添加
@implementation TestAppDelegate
@synthesize textField;
但我仍然得到一個錯誤。我只想知道是否可以從AppDelegate方法訪問它。
如果你在你的項目UIViewController
類,並且正在使用界面生成器,你要訪問您的UITextField
從AppDelegate中,您的項目應該是這個樣子:
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
MyAppDelegate.m
@implementation MyAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MyViewController *viewController = (MyViewController *)[_window rootViewController];
[[viewController textField] setText:@"It should work!"]
}
@end
謝謝你的作品! – user2037696
......你得到了什麼錯誤? – Kevin
您不應該訪問AppDelegate中的任何內容。 – Fogmeister
如果您在編寫更好的問題方面付出了一些努力,您可以希望得到答案並解決您的問題。 –