I would like to be able to drag a cell over another cell, and when I release it would effectively "merge" the cells (display a different cell). I'm not sure if a UITableView
is the best control or a UICollectionView
. Does anyone have any thoughts on how to proceed?
May be I didn't get u properly but as I got, u want to merge cells by dragging so implement some code for you.Have a look at this.
If u Wanna something like this...
use editing code like that :---
ViewDidLoad initializing array and set table to edit mode as:
fruitsArray=[[NSMutableArray alloc] initWithObjects:@"Apple",@"Banana",@"Mango",@"Guava",@"PineApple",@"Watermelon",@"Grapes",@"GroundNut",@"Muskmelon",@"Orange",@"Cherry",nil];
[tblView setEditing:YES];
datasources for tableView set as:->
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
if (sourceIndexPath.row!=destinationIndexPath.row) {
NSString *sourceString=[fruitsArray objectAtIndex:sourceIndexPath.row];
NSString *destinationString=[fruitsArray objectAtIndex:destinationIndexPath.row];
destinationString=[destinationString stringByAppendingFormat:@",%@",sourceString];
[fruitsArray replaceObjectAtIndex:destinationIndexPath.row withObject:destinationString];
[fruitsArray removeObjectAtIndex:sourceIndexPath.row];
[tblView reloadData];
}
}
Try this sampleCode
Here's the solution I used to develop it in pseudocode.
UILongPressGestureRecognizer
to the UITableViewUIGestureRecognizerStateBegan
, use the [UITableView indexPathForRowAtPoint]
in order to determine what cell is being "long pressed". You will turn this cell into the hover UITableViewCell
.UIGraphicsBeginImageContextWithOptions
to render an image of the actual UITableViewCell contents. Create a UIImageView
and add some custom chrome to it (shadows, etc.)UIGestureRecognizerStateChanged
, calculate the location of the hover UITableViewCell
in the UITableView
and animate the pinned cell. (You will also want to toggle the animation for the previously highlighted pinned cell).UITableView
all in a beginUpdates
call.There are a few other things to watch out for such as scrolling when you hit a boundary condition, dropping the hover cell over the original location, etc. but that's the basic gist of it. Hopefully that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With