Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
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?
 

Attachments

  • iphone_page.jpg
    iphone_page.jpg
    55.7 KB · Views: 182
I found 'Tags' I think I can use them to isolate the separate Textfields.
 
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.
 
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?
 
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.
 
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?
 
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.
 
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.