Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
i have a custom cell i want to delete it when a button is clicked situated on the custom cell itself.how do i achieve this. someone help i am stuck at this from many days
Not sure why you want to do this instead of using the standard delete behavior, but...
First you need to know the indexPath for the cell on which that button is being pressed. So you have to wire the custom cell to receive the button action, and then call the table's indexPathForCell method with that cell to get the indexPath.
Once you have it, you put the indexPath inside an NSArray and pass it to the table's deleteRowsAtIndexPaths method (and also choose the type of animation for removing the cell). This will also invoke the dataSource's commitEditingStyle method to let you delete the underlying data as well.
Keep in mind that by doing it this way, you're bypassing the two-step delete process that is built into the table -- where the user would normally request a delete and then have to confirm it. So for the sake of safety, you'll probably want to implement something like that yourself.
Also, the default behavior for swiping across a table cell is to bring up the delete button. You may want to override the editingStyleForRowAtIndexPath delegate method and return UITableViewCellEditingStyleNone for that cell so it doesn't do the default thing.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have already tried to implement UISwitch in the tabeleview cell,now the switch state is automatically changed while i scroll and change the view ,
Please guide me....
You can use NSMutableDictionary for holding the information regarding particular cell UISwitch object. If you have enable a UISwitch button for a cell then set Bool yes and tag value as well in the NSMutableDictionary.
Enable the switch for a particular cell object according to NSMutableDictionary values in cellFor rowAtIndexPath.
UITableview reuses the cells, to solve your problem you need to create NSArray for switch states and assign as user scroll up and down (Using NSIndexPath).
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 .
This question already has an answer here:
Smooth reload of uitableview data when rows are deleted
(1 answer)
Closed 8 years ago.
i am using custom cell in uitableview cell.I am giving button on the right of the navigation bar .if user click on the button the delete cell option has to come like default cell delete option...can any one share code ...thanks in advance....
To delete a UITableViewCell, you should remove the data from the Array that populated the tableview. You can remove it using any logic, and the value of the row returned from the touch.
After that, a simple [tableView reloadData]; will do the trick.
Whenever you click the button corresponding the custom cell you should move the data of the next concurrent cells to their previous cell and then call [reloadData]
check this may help
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.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
UITableView is a very powerful class, powering many navigation and preference views on iPhone. Many people have come up with useful UITableView tips, tricks and samples:
various ways to use Interface Builder for table cells
how to create preference-style cells
ensuring good scrolling speed
etc.
Please post your favourite tips on using UITableView, one tip per question. I'll start by posting the ones I found on Stack Overflow and the ones from my bookmarks.
Ever wondered what UITableViewController really does?
In viewWillAppear, it deselects any selected rows, with animated:YES.
This by the way is why when you navigate back in UINavigationController, the row you've previously touched is nicely deselected with animation. When you pushed a new view controller onto UINavigationController, you've left the row selected. When you pop it and go back to the table view, viewWillAppear fires and deselects the row. UINavigationController does not even know about this happening.
In viewWillAppear, it calls reloadData if the table view contains no rows.
In viewDidAppear, it calls flashScrollIndicators.
It monitors the keyboard appearing and disappearing and resizes the table view appropriately so that when you tap a text field in a table view, it remains visible after the keyboard appears.
If you don't need the keyboard monitoring behaviour, it is fairly easy to do everything else yourself if you need to.
Implementing “checkmarks” in editing mode to manipulate several rows at once: “Multiple row selection and editing in a UITableView” from the great Cocoa With Love blog.
How to implement a custom cell background view?
An excellent sample class by Mike Akers in “How to customize the background/border colors of a grouped table view?” on Stack Overflow.
If you want to remove the separator lines, use this:
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
To ensure good performance scrolling, it's important to avoid transparency in any element if possible - so if you are creating custom cells make them all opaque and set the backgrounds correctly.
You can use the Core Animation Performance Tool to visually see how much transparency you have going on in a cell - you have to be running on the device to use this tool.
Implementing Preferences-style grouped tables: Three20 library (extracted from Facebook iPhone app) has a set of ready-made cells that contain various controls.
(Not sure you want to use them, however. Three20 suffers from “not-invented-here” a little bit and tries to subclass and extend everything, so adding it adds quite a bit of a mess to your project. But at least you can use it as an example.)
How to use Interface Builder to author your cells? Find answers on a separate Stack Overflow discussion: “Using Interface Builder for UITableView’s”