Is there anyway to turn off the Swipe to Delete resizing / shifting the cell? There is a custom cell that we are using that has a UIImageView as part of the cell display. When the swipe is done, it shifts to the left which is what we don't want. If we turn off autosizing in the IB, then the UIImageView does not shift, but then rotate is broke (UIView will not autoresize).
There are probably other ways around this, but was wondering if one can turn off the swipe to delete shift cells.
Ort11, don't touch "autosizing" (this is related to resizing when, for example, rotating - at least, that is what I think you mean). Instead, look at the UITableViewDelegate protocol. There is a method tableView:shouldIndentWhileEditingRowAtIndexPath:, for example. There also is a method to prevent editing for individual cells, in case you want to. All the best -
Perhaps this is what you're looking for?
UITableView disable swipe to delete, but still have delete in Edit mode?
In that you can no longer swipe to delete the cell, but you can still perhaps delete the cell by hitting the edit button.
Of course - this may not help with the moving of the cell parts; when the delete button appears on the cell the contents will still shift. You can override -(void)layoutSubviews in your UITableViewCell, to customize how the delete button will be positioned (more here: iPhone UITableView - Delete Button)
Related
I need help implementing a drag and drop gesture, I would like to know Your opinion to find the best approach.
I have a view controller with a uitableview on the right and some image views on the left.
I would like to allow the user to drag every cell of the table view on one of the image views. Basically the drag-n-drop will fail if the cell is not released on one of the image views, otherwise the image view will change image according to the dropped cell.
What do You think is the best way to achieve this?
In addition, when the user start dragging, I would like that he drags around a particular shaped subview, with image and data, not drag the semitransparent cell.
Thanks,
The basic steps for this would be:
Add a long press gesture recognizer to your table view (the whole view, not individual cells)
When the gesture begins, find which cell it is over (convert point, then user indexPathForRowAtPoint to get the cell)
Make a copy of that cell which will become the dragged view (take a snapshot, add it to a UIImageView and add that to your main view). Or you could make the view look however you want if you dont want it to look like the cell
make your original cell hidden so it looks like it is being dragged
On gesture changed, move teh position of this image view based on locationInView of the gesture)
On gesture ended, check to see if the cell is over an image (hitTest: for this) and do any animations or calculations you need.
i want to implement delete row with animation like this video.
Now deleting of row is easy task now i have question regarding how to manage animation like above video with UITable or any other control.
i refer some instance method. for tableview.
But in this, i am not getting how to manage animation like move row on touch in tableview.
Any suggestion appreciated.
Thanks
The animation would need to be a custom implementation. I would recommend having a subview on the UITableViewCell (the subview would be the red, the table view cell's background would be the black), and place a UIPanGestureRecognizer on the subview. You'd then need to move the subview as the user pans (in the gesture recognizer's method that is triggered), and do the math to know when the row should be deleted. Then you would just use the native iOS delete row method:
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
I found such cool custom control based on UITableView which provide exact animation i actually required.
You can found code here.
I've got an array of buttons in a UITableViewCell.
I populated them all through the cellForRowAtIndexPath method, but my tableview gets sluggish even though I have released everything.
Should I be using a custom UITableViewCell to populate?
Any suggestions on how to make this as smooth as possible for the user would be great.
Screenshot below.
You could create a custom cell / custom view pair for this specific cell, where you can draw all yours buttons in drawRect:. However, this would essentially draw all your buttons as an image so you wouldn't be able to tap them, but I guess you can always create a UITapGestureRecognizer to your cell (you'd still have to figure out which button was pressed by examining x,y values).
Still, I don't see any point in adding your tag buttons inside a UITableViewCell. You could come up for an alternate design in your UI, i.e. a UIView presented on top of the table, or a modal controller maybe.
How can I create a custom scrollbar for a UITableView?
I want to remove the default one that pops up when tracking begins and that disappears when tracking ends. I want, instead, to have one similar to that in a computer program: (a) it's on the right side of the screen and permanently visible; (b) manually scrolling the bar will scroll the UITableView to the appropriate position; (c) scrolling the UITableView will scroll the scroll bar appropriately (without showing the default one that Apple provides).
The difficulty in (b) and (c) is that, as far as I know, Apple only provides methods to scroll to a particular row/section, but not to scroll to three-fourths of the way down a row. So, for example, if I want to scroll the scroll bar, the UITableView will subsequently only scroll to the top of a row/cell. The method I'm talking about is:
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated
Has anyone implemented a custom scroll bar in their UITableView before? Or can someone help me figure out a way to solve the following problems:
scrolling to any point in the UITableView instead of to the start of a cell
removing the default scroll bar and preventing it from appearing
changing the scroll bar image/animation/whatever as the UITableView is scrolled
Thanks!
UITableView inherits from UIScrollView, that means you can use any of the existing functions. In your case
– (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
should do the job. It moves the table to any position you want.
To disable the existing scroll indicator, use
table.showsVerticalScrollIndicator = NO;
And to add your own, just add your custom view!
How do we go about coding drag-and-drop (or tap-and-drag) from a cell in a TableView on an iPhone? I'd like to have a set of drop destination icons that are stationary. I've been trying touchesBegan, touchesMoved and touchedEnded methods. These events fire nicely from a View so I can get a swipe to work nicely. Most likely the destination icons will be in a View so I think we are trying to get the drag-and-drop to begin in a TableView cell and end on an icon on a View that is beside the TableView.
Are you trying to drag the entire UITableViewCell, or a UIView inside the cell? Either way, I don't think you'll be able to move the view outside the bounds of its parent, which would be the UITableView.
I have another project where I have a icon or tile (UIImageView) that the user can drag around the screen. After it reaches a certain distance, it snaps back.
Similarly, a possible solution might involve popping up a UIView (perhaps a UIImageView) over top of the table cell when the cell is tapped. The user could drag that around the screen, and you could make it disappear when it's "dropped" on whatever target you have.