Removing UITextFields.

Discussion in 'iOS Programming' started by larswik, Sep 25, 2011.

  1. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    My little app is coming along and everything is working so far. I am tryign to find out if I can remove UITextFields programaticly. In the Photo the User presses the + key and that adds a row of 3 items. I added a trash can to remove them, not as easy.

    I have a way I am working on that when the user backs out of this page the TextFields are saved to an Array or Dict. Then when they enter the page again I can count the items in the array, use a for loop to add the textFields back in and add the content to them.

    But if they want to remove it by clicking on the trash can, I am drawing a blank. Since I add them programaticly I don't think they have unique identifiers. But if they are selected then the are the first responder and I might be able to delete it that way. Any ideas where I should look?
     

    Attached Files:

  2. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #2
    I found 'Tags' I think I can use them to isolate the separate Textfields.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    Why do you even want to remove the textFields? Seems rather unusual.
     
  4. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #4
    If the user wants to delete a row. If they paid off that bill or added to many UITextFields. I got it to remove but not the way I wanted to. Using this code it deletes it right after they touch the field, not what I wanted but It removes them.
    Code:
    -(void)textFieldDidBeginEditing:(UITextField *)textField {
        currentTagNumber = textField.tag; //assigning textField Tag to int
        [textField removeFromSuperview]; //testing to see if this code removes it
    }
    
    Right now I am trying to get the tag number from the currently selected UITextField and add that to my Method that I have for my trash can button.
    So Pseudo code

    -(void)trashCanButton
    [textField with this tag removeFromSuperView]

    That is what I am trying to figure out now.
     
  5. admanimal macrumors 68040

    Joined:
    Apr 22, 2005
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    That's what I was gonna say. Then you could just delete the row of the table.
     
  7. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #7
    I have not forgotten about the UITableView. But I thought I was limited with that. I want to background photo like above of paper and I wanted 3 TextFields for the user to enter numbers in. Can I add 3 UITextFields to a UITableView cell?
     
  8. admanimal macrumors 68040

    Joined:
    Apr 22, 2005
    #8
    A UITableViewCell is just a view. You can add whatever you want to it. You can make the table view transparent and use your background image, or you can do something creative with how each cell looks to achieve a similar effect without any images.
     
  9. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
  10. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #10
    The question that shouted at me was "when the user taps the delete button, which row will be deleted?". In other words, how does the user delete a particular row using your user experience?
     
  11. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #11
    My thought for that was since the UITextfields had Tags numbers assigned to them row1 is 1-2-3, row2 4-5-6. So if UITextField tag 1 is deleted then then the other 2 are deleted by default, or so I thought.

    Looks like I should backtrack a little and use UITables instead.

    Thanks.
     
  12. admanimal macrumors 68040

    Joined:
    Apr 22, 2005
    #12
    I think jiminaus meant how will a user actually choose which row to delete.
     
  13. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #13
    Simply deleting the last row that was selected doesn't seem like it would be the most intuitive thing from the iPhone user's perspective...

    Instead, it seems like using a UITableView that allows the swipe to delete gesture would be a better idea...

    you can set the backgrounds of the cells to be a yellow gradient and the borders to be the blue line, if you'd like to keep the yellow notepad look of your app.
     
  14. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #14
    Thanks I am reading up on the UITableView now. I think I can use the same idea of adding the UITextFields but add them to a UITableCell. I am going through some tutorials on them right now.
     

Share This Page