UITextField and UITableViews... Am I doing this correctly? If not, what is the best way? - iphone

I have an array of folders. Each folder is listed as a table view row.
When I display my table, I populate it with a set of textfields on the left hand side of the row (i want the user to be able to edit them) and a set of switches (on/off) on the right hand side of the row.
All is working well, you can touch the textfield and the keyboard appears. You can changed the values of the switch each time also.
The problem I'm having is knowing which text field has been changed so that I can update my array ready to save the values.
I'm using..
[textField addTarget:self action:#selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];
and...
-(void)textFieldDone:(UITextField *)textField
The problem is that the textField object does not contain any unique information about it in the textFieldDone selector. I've tried setting
[textField setTag:rowNumber];
But it doesn't show as tag is not part of the textField object.
Anyone any ideas on the best way of doing this? Surely there must be lots of applications that have have textfields in table rows that you can switch between?
Or maybe I'm missing something here....

Actually 'tag' is part of the UITextField as it is inherited from UIView.
Maybe I can suggest a different approach. Use your table view to display the data with a checkmark in the accessory view if the boolean value you are representing with a switch currently is set to YES. When the user taps that row, push a new view controller that contains a text field and a switch that the user can edit.
Is there an application you've seen that uses the UI method your attempting with the text field and switch in a table cell?
Keep in mind that you are probably reusing table cells, which is what you're supposed to do, however you may not be setting the tag on subsequent uses of that cell. Just guessing here.

Related

*Editable* Labels of UITableviewCell

I am asking this question as I didn't get any proper/relevant answer
(means I got the answer but not in the form that I want).
Hope anyone of you can provide me the right solution.
OK , My Question is about editable labels.
I have one table view that contains customized cell(s) with 6 different labels in each cell.
What I Want :
1) I want to edit the label when user touches it (Changes will be
saved).
2) When some save button is pressed, I want all the values from the
table view to be saved in an array.
I am attaching screenshot herewith (Hope it may help you to understand my question).
Note :
In the above screenshot what i want is when user touches the "Cotton" word, It can be editable and when user touches the next word (suppose "Pallet") , change in the first word (means in "Cotton") must be saved. There will be one button called "Save"(not in screenshot). When user presses "Save" button , all the values of Tableview should be saved in some array.
It will be very helpful if you can provide me the answer with relevant code.
First of all, in this case, it is best to forget about using labels and use UITextField instead. If you implement UITextFieldDelegate's methods, they will let you know when one starts editing or finishes.
So here is what I would do. Create a subclass of UITableViewCell and make it look exactly how you want it to. Also, it should also have an NSIndexPath property, so you will always know exactly which row gets edited. (if your cells look anything like those in the screen-shots you provided, this step should be rather easy)
Also, it should implement the UITextFieldDelegate protocol and also create one that will let you know when a cell has been edited so you can save it's contents.
In your controller, you should create a temporary array that will be a copy of you data source. When a cell gets edited, you should update the info in your temporary array. On pressing save, you should save this array and make it the data source. Else, just set it to nil and ARC will take care of it.
I can't provide you with code for now, but it shouldn't be hard to code it once you understand the logic.
You have to subclass UItextField so that they can store rowNumber and productName.
Change the UITextField appearance when user taps on it you can catch the touch event on textFieldDidBeginEditing,
And save your Data for a particular row in a dictionary then this dictionary could be saved in an array pointing to the rows of the table .

IPhone need design idea for tableview

i have a UITableView where i want one cell(database row) needs to be default,
So I am thinking of two options
in TableView upon clicking a cell, change accessoryType to mark just like ringtone selection in settings app
when user enters data, add an option (like radio button or segmented control) to make that cell (database row) as default one
I feel first option is good but we can implement code for that only in didSelectRowAtIndexPath but i need to jump to another view when user click on a cell.
So please give me an idea how to accomplish this
One idea iam thinking is adding an edit button but don't know whether its possible or not.
Thanks
Not sure if i understand your question correctly , but according to what i understand you want a table view in which many values will be there , and you want one value to be default which can be changed later.
According to me these ways would be pretty good,
Changing the accessorytype of the tableViewCell. (Most common way)
Changing the Highlighted property of the cell on loading the tableView.
Adding some image then setting the image as the background view of the selected cell.
Adding custom image view (such as tick or something and adding to the cell).
this code can be put in the viewDidload so your default selected value appears.
Hope this helps.
Don't know what you mean by default. I'm assuming you mean already selected. You might just want to set the accessoryType to the checkbox. That would be Apple's way of doing it.

How do I make an editable detail view on the iPhone with a grouped UITableView?

I want to make a grouped TableView similar to the Apple iPhone contacts application.
I need a lot of standard fields which can be edited, but I would only like them editable once the edit button in the navbar is clicked.
This has been bothering me forever that I could not find a good tutorial.
Thanks in advance.
This is not easy. I just built the same thing because there is nothing available from Apple. I ended up creating a single table cell with a UILabel and a UIView on it. The UILabel is for when the cell is in read mode, and the UIView is for editing. The UIView contains a number of UITextFields. These are the individual fields. I also had to implement drawing code to draw the lines between the fields. Then I had to come up with the code to pass in an address object, load it into the fields, format the text for the label, switch in and out of editing mode (with animation), and finally handling saving of changes and canceling. As yet it doesn't handle tapping the address type to select that from a popup list, but I have most of the code in place for the rest.
This could have been done using individual table view cells for each field. But then you can't select the whole thing the way it does in contacts and adding and deleting addresses becomes trickier.

How to deal with Custom Cells when these are not visible and want to get the cell using indexPath?

Guys, I didn't find a clean and a simple solution for the following issue. I've a UITableViewController view which uses a UITextFieldCustomCell that I implemented.
The table has several rows, that requires the user to scroll down an enter values on each cell, which contains a UILabel and a UITextField.
Every time the user change the value on the UITextField the UIViewController gets notified and stores the value in a NSDictionary using the cell indexPath.row property, in order to identify what's the key for the cell where the value needs to be stored.
The problem is if the user keep focus on a cell and then scrolls up or down (removing the cell from the view) makes me unable to get the indexPath for the cell, since it's not visible.
So, I cannot store the value since I don't know from which cell the value is coming.
Have anyone run through this issue before?. It seems to be a common design between iPhone applications, does anyone have an idea if is this a good implementation or not?
Thanks!
I assume you're observing textFieldDidEndEditing:. Are you saying it's not firing, or that it is firing, but it's no longer in any of the cells (possibly because it's in the process of being removed)?
Assuming the latter, my approach would be to use setTag: on the UITextField to make it easy to keep track of its index. This would save you from ever hunting around in your cells, even in the case that they are on the screen.

Three20 TTSectionedDataSource row height

I'm using Three20 to create a table with several textfields for user registration. I've found two possible methods using Three20. The first uses the TTSectionedDataSource's tableDidLoadModel method to manually add UI components and the second adds custom items that contains pre formatted UI components. The second option seems way more complex and I'm having a difficult time accessing the individual fields. So if one field is a textfield for the username, I need to access the field to submit the username and it doesn't seem like there's an easy answer. The first option gives me a lot of flexibility, but I can't figure out how to set the individual row heights. One row may have a label above a text field, another may have an image, etc. Is there a method that can be used in TTSectionedDataSource that will allow me to set the height for each row? Thus far, I'm using method one and creating UIViews to hold a label field and a text field. I've tried changing the frame of the uiview before it is added to the items array, but it has no affect.
Any ideas?
I believe I may have figured it out. Not sure if this is the correct solution, but it seems to be working.
First in my custom item class I pass the datasource as a delegate. Now that the delegate is part of the item, I can pass it to my textfield as the delegate. As long as I include UITextFieldDelegate in my data source class, it will respond as the delegate to my textfield. So that's getting the content from the textfield.
If I want to change the content in a textfield from the datasource, I can leverage the method:
- (void)tableView:(UITableView*)tableView cell:(UITableViewCell*)cell willAppearAtIndexPath:(NSIndexPath*)indexPath
I can check the row using indexPath.row then type the cell as the corresponding custom cell class. From there I can access any public methods in my cell class. So I created one that returns a reference to the textfield. So I can say:
[[(MyCustomTextFieldCell *)cell theTextField] setText:#"hello world"];
Next step is to assign it to a local ivar and then I'm assuming I should be able to access it at any time.
The main reason I want to be able to modify the content of the textfield is that in certain instances by clicking on the textfield, a picker will come up and the results of the picker are formatted and inserted back into the textfield.
Please let me know if my approach is too convoluted. Perhaps I'll create a sample and post it for everyone to rip apart and tell me I'm a moron and there's a better way.
thanks,
howie