-1

Is there a way to get some input data from user using a kind a prompt alert?

In my Mac OS X app I need user to introduce some text into a textfield.

I've tried with segues (by building a new view) but I need my program to wait until user complete that textfield.

Xcode is presenting my new view and then runs through all my function and that is not what I need.

On short, I need user to press a button, program to wait for text box completion and then, after pressing OK button (from prompt view or whatever), program to continue.

In C#, I've managed that with showDialog.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Ady Năstase
  • 249
  • 2
  • 9
  • well, show the view when the user is pressing the button. But if you want an alert you could check UIAlertViewController. Here you can pass actions and maybe also textFields. In UIAlertView it was possible to use TextFields, but there deprecated in swift 2.0 if iam not wrong – Björn Ro Oct 04 '15 at 20:45
  • Possible duplicate of: http://stackoverflow.com/questions/29433487/create-an-nsalert-with-swift – Eric Aya Oct 04 '15 at 20:51
  • 1
    Possible duplicate of [Access input from UIAlertController](http://stackoverflow.com/questions/24172593/access-input-from-uialertcontroller) – AaoIi Oct 04 '15 at 20:54

1 Answers1

0

If you want to wait till the user is finishing the TextField than you can set to the textView a delegate. This could be the controller itself.

Than you implement the required Protocol and implement the functions for textFieldDidEndEditing. Here you also have the TextField that is ended ad a param and you can get the value from the text on it

Here you know that the user removed the keyboard and you can go forward.

You can also use a Button and add a action to it, so if the user taps the Button your program can proceed. You only need to get the value of the TextField. Maybe you stored it in a property :)

Björn Ro
  • 780
  • 3
  • 9
  • I have added a button in my "second" view but my code from "the first one" is running after the second view is segued. And that's my problem... – Ady Năstase Oct 04 '15 at 20:54
  • i see, so you see the possible duplicate links in the other comments :) hope they will help you – Björn Ro Oct 04 '15 at 20:55
  • but i think you have an design issue. Why do you want to run code and separately wait till the user is done with the TextField? If you have to stop something because of dynamical changes, you should store the process and start again with new data. But only a suggestion :) – Björn Ro Oct 04 '15 at 20:57
  • That could be a way to do it. Thanks. – Ady Năstase Oct 04 '15 at 20:59