Change UITableViewCell appearance when drag handle is pressed - iphone

I'd like to change the appearance of a cell when the user tap the drag handle.
I searched in the documentation, forums and google, but I can't find a method or an event that say when the drag icon is pressed.
Any help will be appreciated!
Thanks

Does this function help:
// Allows customization of the target row for a particular row as it is being moved/reordered
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath;
It doesn't seem to fire until the cell has been dragged about half way into another cell, though.
It is the only indication I could find that a cell is moving.

Related

Iphone: UITableView how to detect that row is selected

I have a UITableView, and I press the row, but do not release finger, so didSelectRowAtIndexPath is not called yet, right?
How to detect on which row i clicked? in which method?
How to detect that I clicked on table view? Is there any method like rowIsPressed? or onTableViewTouchDown?
There are two options at least:
1) You can subclass UITableViewCell and than use the touchhandling you know from a default uiview. (Like touchesBegan: etc.) / OR add a custom uiview as contentView of the tablecell.
2) Add a gesturerecognizer to each tablecell.
To find out in which row you are, you could give every row a tag (which than refers to the row) in cellForRow:atIndexPath:
try this
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
There is no such method to detect the selected state before lifting the finger... I guess you should override the UITableView class and add a UIGestureRecognizer to it.
And about your second question, I think you are talking about this table view delegate method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
But there is also another method that will give you the current selected row. This is it (directly from the table view class):
- (NSIndexPath *)indexPathForSelectedRow
Hope to have helped!

How to display the selected cell in highlighted state when i come back in UITableView?

I created a custom cell for my table view and for the most part everything seems to be working fine, but when I select one of the rows (which takes me to another UIView), then come back from the subsequent view via the nav controller, the selected cell is not in highlighted state. How to display the selected cell in highlighted state when i come back?
any help is appreciated in advance, thanks.
when you are coming back from anotherview make sure that save the selectedCell and then in viewwillappear method reloaddata.in cellforindexpath write the code of selection style uitableviewcellselectionstyleblue
As #sachin said, you should save selected index path
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedIndexPath = indexPath;
}
and in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
You should check if indexPath is equal to selectedIndexPath,
but you should be aware that Apple discoureges that kind of behavior in HIG: http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/MobileHIG/UIElementGuidelines/UIElementGuidelines.html
In rare cases, a row might remain highlighted when secondary details
or controls related to the row item are displayed in the same screen.
However, this is not encouraged because it is difficult to display
simultaneously a list of choices, a selected item, and related details
or controls without creating an uncomfortably crowded layout.

Question about iPad/iPhone controls

On the iPhone/iPad in the general settings they have a list of itms that display a '>' at the right hand side. When pressed it slides to another view.
Is this a control from the object palette? If so, which control? If not, what is the best way to achieve similar functionality.
I have looked at a lot of the samples on the Apple Dev site, but I cannot find a control like that, or at least I don't remember seeing it.
Any help on this foolish question is appreciated!! -:)
Thanks
Any time you see a view that is a scrollable list of items, you are looking at a UITableView, and each item in the list is defined using a UITableViewCell. To make the UITableViewCell show the '>', you simply have to set its 'accessoryType' to 'UITableViewCellAccessoryTypeDisclosureIndicator'.
This only draws the '>', it doesn't slide in the other view. However, when a user selects a UITableViewCell, it will call a function on its delegate:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
In here, you will write the logic that slides in the new view controller (using UINavigationController's -pushViewController:animated:).
To learn more about how to use UITableView, I would highly suggest reading through the UITableView programming guide. It also links to downloadable projects with sample code.
You probably mean the combination of a UITableViewController and a UINavigationController. Create a new "navigation based app" to check out how it works & have fun. :)
Both are available in IB under the Controllers section.
The control you're looking for is a UITableview with disclosure indicators. To get the disclosure indicators (either the grey chevrons or the blue buttons), set editingAccessoryType for each tableview cell. That will give you a '>' on the right side of each item in your tableview.
When you tap on one of the '>'s, the tableview's delegate will have this method called:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
This is different from the method that is called if you tap anywhere else on the row:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
As dominostars said, you create another view and use UIViewController's pushViewController method to have another view slide in from the right.

drag and drop in uitableview

I am currently developing an application in which a user is displayed a list in the form of a tableview. when the user selects a particular row, he/she can drag it to another row. When that happens an alert is displayed giving some specific information.Any idea as to how it can be done.?
What I am doing is that I am using gesture recognizers.When a particular row is selected, an image of the selected row is made which then is dragged to the specific table view cell.I am able to move the image but my problem is that if I dont put the imageView under a UIView, the dragging stuff does not happen.....
My dragging code is based on apple's touches sample code .
Update:
After trying for some time, I am able to almost implement this.I still have one doubt though.. I am creating an image of a cell once it is tapped.Then UIPanGestureRecognizer has been added to that imageView which it turn makes its movement possible .The only problem is how can I know on which cell the image has been dropped?
you should implement:
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
which will return YES, and also implememt:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
//do whatever u want after row has been moved
}
and then call this function from tableView:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
to enter to edit mode.
This is a sample of an application with cells drag-n-drop in UITableView using native methods of delegate and dataSource of UITableView.
https://github.com/coderDove/UITableView-Drag-n-Drop

Distinguish between click on AccessoryView and Cell Content and will Apple allow it?(iPhone)

I was wondering if there is a delegate method to implement that let's me distinguish between a tap on the content view of the cell and the disclosure symbol to the right.
I would like to send the user to two different view depending on where on the cell they tap.
I think the event is normally caught by testing if the tableView is:
(self.editing)
I can only remember having seen this functionality during editing in the Alarm Clock and Address Book app. Does anyone know if it is even "allowed" by Apple or is it considered "bad" user interface design? Anyone know of other Apple apps that implements this approach?
Hope someone can shed a little light on this issue:)
Thank you
Implement the Delegate method to handle taps on accessory button
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;
And you know how to handle cell selection..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;