UITableView - how to recognize if i drag a cell over a cell? - ios

I want to recognize when i select a cell and drag it over another cell.
Is there any example/ workaround for this?
My goal is to create an UITableView which allows me to merge two cells into one cell.
Thanks

You can use UITableView delegates
to move rows
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
And To compare CGRects
self.tableView rectForRowAtIndexPath:(NSIndexPath *)
Then, I believe, create, insert new cell.

Related

Table view first cell always same

well my issue is:
I want to have table view but I want to keep first cell always first , and never let it scroll
but other cells should scroll.
can someone please suggest me how to do so ?
If your table have only one section than create custom view like cell and add this view in
table delegate method
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
like
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
return <Your View>
}
but it works if and only if one section in given in table.
The above answer with the static cell in the header works.
You might want to create another tableview just above the present one, with just static cells in it. Just below this table view, keep the present one with (number of all cells - number of static cells) without any offset. It looks as just one table view. This way, you can have more than one static cell with all the properties of a Tableview cell.

Using the UIView-Glow category on UITableViewCell

I'm using the UIView-Glow category trying to highlight certain UITableViewCells. But it doesn't work if it's used in tableView:cellForRowAtIndexPath:.
I guess it must be used after the certain view appeared on the screen. So, is there a possibility to let certain UITableViewCells glow (even when scrolling the table view)?
Yes, there is possibility to let certain UITableViewCells glow with the category file you mentioned. You need to call the category methods in the table view delegate willDisplayCell instead of cellForRowAtIndexPath.
For example:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell startGlowing];
}

uitableview drag and drop with not moving cells

I would like to make use of the drag and drop reordering of tableview cells, but I have one problem:
I would like to keep my first row in place!
Here is the canMoveRowAtIndexPath delegate function:
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==0) {
return NO;
}
return YES;
}
If I do it like this, the first row can not be dragged, BUT you can still drag another row on top of it! Is there any way to prevent cells from dropping 'above' this row?
Your answer is hear,
You can use these step.
Examples of Moving a Row
check if it is a drag and cancel the scrolling if it is = [uitableview setScrollEnabled:NO]
read this thread, it will help you i hope
Tutorial on How to drag and drop item from UITableView to UITableView

iOS: How to add/insert specific cell with identifier into UITableView?

I have grouped static cells in a UITableView. Now I'd like to add or delete (what is easier?) one specific cell, which I've already created in my storyboard. It depends on one NSString: If my string == YES, the cell should be displayed, else it shouldn't.
already tried tableView:insertRowsAtIndexPaths:withRowAnimation:
What you need is:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
This method is part of the UITableViewDelegate protocol and will be called when the table view is about to draw a cell for a particular row. This provides a UITableViewCell for you to work with.
To identify which cell you need to hide, you can add a tag to the UITableViewCell in the storyboard. This is easier because you are adding static cells.
Then you can just do:
if ([cell tag] == someInteger) {
cell.hidden = YES;
}
You can wrap this in a condition based on the value of your string that you have mentioned.
I have added some example code on Github to illustrate this.

Manage Swapping between two cells rather than changing the NSIndexpath of other UITableViewcells

I know it's the default property of rearrangement of tableviewcells when UITableView is in editing mode & user just reorder the Rows which is handled by UITableViewController.
As per Apple Doc : Reordering of Rows
Now what I want to do is, when I drag the cell over other cells, the backend cells should not get rearranged automatically, just the cell on which I drop the dragged cell should gets rearranged, a kind of Swapping between two cells.
For better understanding, please refer the below image. I should be able to Shift Jones to Room1 & the tableview controller should able to automatically be shifting Smith2 to Room3.
Below are delegates methods which I am using :
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
NSString *temp = [roomstoringArray objectAtIndex:sourceIndexPath.row];
[roomstoringArray removeObjectAtIndex:sourceIndexPath.row];
[roomstoringArray insertObject:temp atIndex:destinationIndexPath.row];
// [temp release];
}
Problem is :
How can I stop other cells to get rearranged automatically while I
am dragging the cells over other.
There none of the delegate method which gets called when one used to
Drag the cell over others, only method called is
moveRowAtIndexPath when one drop the cell on it. So, even can't check for some condition & didn't find any scope of this enhancement
within existing TableView.
Is there any property with the TableView where I can stop such kind of behavior to perform the swapping between two cells only where rest of rows remain at the same indexPath.Alos, can someone please help me out with some-other way,if any.
For Problem you mention, Please check UITableView Delegates from here.
Below methods are helpful to you.
targetIndexPathForMoveFromRowAtIndexPath
canMoveRowAtIndexPath
For Swap b/w two rows you can get idea by this answer.

Resources