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 .
Related
I am new at iOS development and i have some issue of cellForRowAtIndexPath method of UITableView.
In my application i have multiple rows in UITableView. when i want to see each row then obviously i need to scroll UITableView.also in UITableView i added UITextField to each UITableViewCell . when i add value
of UITextField in DataBase then its work properly but when i want to edit values of UITextField and i add values of TextField in DataBase then problem is created.
PROBLEM :- If i want to add all editable values of TextField in DataBase then i must need to be scroll UITableView up to down. if i do not scroll then invisible TextField is not add in DataBase :( Here in my Application add and editing are in same UIViewController base on ID that i passed.
by Googling i also found that cellForRowAtIndexPath is not called for all rows. It is only called for visible rows and then called for additional rows as the user scrolls to them. Old rows are also destroyed as they go off the screen and it will request the cells again if the user scrolls back up.
so, please help me how can i solve my problem,
EDIT FOR MORE EASY TO UNDERSTAND MY PROBLEM :
For Example :
I have two UIViewController.
1 - FirstViewController
2 - SecondViewController
in FirstViewController display all list of Name in UITableView and it has two choice either select name in UITableView or add new data by tapp BarButton from UINavigationBar .This both processed adding and editing are done in same ViewController called SecondViewController . data (or values) Add by SecondViewController is working properly
But when i select any row ( or name ) from FirstViewController then related ID pass to SecondViewController and all information are display on TextField base on ID. here all values are get from DATABASE and i store it to NSMutableDictionary and then it store on textField by access KEY of Dictionary. but values are store in TextField which are visible. invisible TextField not store values even i get from DATABASE . so i must need to first scroll UITableView.
Thanks in advance :)
Then implement like given below
Get the database value and store it in NSMutableDictionary and accessible through out by declaring in interface or .h file.
Then when each time your tableView or textField loads read the values from dictionary and display.
And in your textFieldDidEnd or textFieldDidChange delegate get the data from textField & save/store back to your dictionary with the same key. This time it just replaces the old value as you know.
At last just save all the dictionary values into your database on backAction or viewWillDisappear method.
This should work for you, if not let me know.
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.
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.
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
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.