disabling textFields.

Discussion in 'iOS Programming' started by larswik, Oct 4, 2011.

  1. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    Is there a way that I can disable all the UITextFields except for the one that is selected until the user presses the return to dismiss the keyboard.

    My code works great but if the user make more then 1 change to a textfield before pressing return it only replaces the last change they made to the Array index. I have been scratching my head trying find a way to do this.

    Any ideas, web links or Doc's?

    Thanks
     
  2. Matthew Yohe macrumors 68020

    Joined:
    Oct 12, 2006
    #2
    You can certainly setEnabled:NO on fields... but this really isn't what you want. (The docs for this is UIControl, since UITextField inherits from that)

    But anyway, back to why you don't want to do that. You actually DO want to allow the user to make any changes they want to any text view and then accept what they entered last as their entry (because... that's what the user did and what they want, so why would you prevent them from doing this?)

    Make sense?
     
  3. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #3
    The issue that I am having is that when ever the user hits the return key the edited text value replaces the value at an index number of an NSMutableArray. If he makes more then 1 change only the last one is recorded and the other default back to the original numbers.

    If I can lock the user out of being able to click any other textFields until he confirms his change this solves the problem.
     
  4. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #4
    No, it would just make your code work, and would frustrate your users. On the iPhone/iPad, a user's tolerance for restriction is next to zero. If you frustrate your users by forcing them to unnaturally have to hit return they'll just abandon your app.

    Really you need to correct the short-falling in your code.
     
  5. sundialsoft macrumors newbie

    sundialsoft

    Joined:
    Sep 2, 2010
    Location:
    Scotland
    #5
    multiple text fields

    Just wanted to confirm that if you want users to be able to move across multiple text fields making entries without touching done/return on the keyboard it can be done but I'm not using a tableview. I have a todo list in a scrollview with 30 entries which users can freely type into and then move to another field without dismissing the keyboard. - (BOOL)textFieldShouldReturn: saves away any entry and I don't lose any content.
     
  6. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #6
    I think a better solution in your code would be making it so that the text fields have a delegate set up to respond whenever the text changes, not just when the return key is hit.

    If you insist on not allowing the user to change multiple fields at once, another solution could be making a modal view that pops up when they tap the field and the modal view is where they make the changes.

    I don't endorse the second possibility I suggest at all. I've seen apps that do this before, and they annoy me a good deal, but at least it's something that has been done before and so would seem more natural to users than having all the other text fields disabled until they hit return on the one they've already selected.
     
  7. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #7
    It is so frustrating. I have probably spent 100 hours writing this class and learning a lot as I do it. I tore it apart once and started over when I began having big issues that I could not explain easily. The new version is less cod and works great except for the user making more then 1 change to existing entries. If the user does not have freedom to click around I can see that as a negative thing now. I do use the (BOOL)textFieldShouldReturn: method and that is where I have the majority of code to write to my arrays.

    Perhaps I could use the - (void)textFieldDidEndEditing: to check if the textfields value has changed. If it has I might then store the the new TextField values, the row and column (column 1 2 3 to array 1 2 or 3). Then when the user hits the return button all the information is written to the at once in the (BOOL)textFieldShouldReturn: code I have.

    Thanks for the suggestions.
     
  8. RonC macrumors regular

    Joined:
    Oct 18, 2007
    Location:
    Chicago-area
    #8
    What you're missing is that these methods are not invoked the way you think they should. You think that when you switch fields it will send you something and it doesn't. Think instead of implementing textField:shouldChangeCharactersInRange:replacementString: to track changes the user makes to the various fields and textFieldDidEndEditing for when they're done. The majority of the work is done by the former method.

    (You may get a textFieldShouldBeginEditing: when the user switches among textFields, but I'm not sure)
     
  9. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006

Share This Page