1

I have 2 textfields in a view. I want to read value of this fields in AppDelagate.m.
It is very strange that does not work me all methods.
I posted my code here:
in First View

    @property (nonatomic, retain) IBOutlet UITextField *Usernametxtbx;
    @property (nonatomic, retain) IBOutlet UITextField *Passwordtxtbx;


Can you help me?

2
  • The app delegate should not have a reference to the UI. The reference to the UI should be in the controller. Of course you could get a reference to the app delegate from the controller and when the fields change then update properties on the app delegate but it is naughty. Commented Apr 30, 2015 at 5:15
  • You need to declare textfields in view controller. Now set values in some preference like User defaults. Now you can use txtfields values in app delegate by calling methods like applicationdidresignactive or applicationdidbecomeactive. Value can't call directly in app delegate. bcoz its a starting point. Commented May 1, 2015 at 13:50

1 Answer 1

0

Its very odd that you need to read the values of outlets in an AppDelegate. AppDelegate is to handle your app delegate methods such as when your app launches or when your app is supposed to enter background.
In didFinishLaunchingWithOptions, the outlets will be nil. You should be doing these tasks in viewDidLoad.

2
  • Thanks @Schemetrical , but i am working on a open source project and i want to change it. It is using a framework that has some event and ... I need username and password in one of the event that handle in app delegate. Commented Apr 30, 2015 at 4:56
  • @Mostafa are you sure its not asking for your client ID and public ID? It should never ask you for dynamic items in appdelegate. Commented Apr 30, 2015 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.