In my application, I have a ViewController (ViewController 1) that has a UITextField and a UIButton. In my ViewController 2, I have a UINavigationBar. I want to be able to type something in the ViewController 1 textfield, press the button, then have the UINavigationBar text in ViewController 2 be set as the UITextField from ViewController 1. But of course, Xcode will not let you declare objects from another ViewController without doing more work. How can I do this?
In my application, I have a ViewController (ViewController 1) that has a UITextField and
Share
Your question is not very clear but from what I could understand you want a
ViewController‘sUIButtonto set theNavigationBar‘s title of a secondViewController?Seems like a pretty weird behavior to me but here’s what I think might help you.
On your first
ViewControllercreate a protocol/delegate functionality so that when yourUIButtonis pressed you can call:And with that send your
UITextField‘s text to yourAppDelegate, or whoever creates these twoViewControllers, and there you will receive that text and send it to your secondViewController.Perhaps you will have to implement a method that changes the title in your second
ViewControllerif that line does not work. Hope this is useful for you and that I understood your question.