customising cell editing style in uitableview in ios - ios

I want to give two options when user swipe right direction.
The two option or button with name edit and delete.
At present it is show only delete when user swipe left i.e UITableViewCellEditingStyleDelete
But i want to customize this view and give two button with gray background.At present it is red background.
The code is :-
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
Please help me how to acheive this.

You need to subclass UITableViewCell and override
setEditing:animated: and
layoutSubviews
This should work in the expected way.

The button is not customisable, if you want to do that behaviour you'll have to create your own custom cells and add the animations yourself.

Related

How to distinguish which item has been selected in UITableViewCell

I'm trying to create a project similar to Instagram. When you select user, it brings you to user VC. When you select comment, it brings you to comment VC.
I have a custom UITableViewCell that has many items in it just like Instagram as mentioned above. What I'm trying to achieve is when user selects any item within a UITableViewCell regardless it is a label, or image, it will do segue to another VC for detailed information.
I'm referring to this post to achieve it, but my concern is how am I going to recognise which has been selected? Because I have an unknown repetitive count of rows.
I don't really need codes as they can most likely be found with thorough searching, though it would be more helpful. But I just need structure because I'm totally lost on how I should do this.
I'm doing this in Swift programming.
Thanks for helping.
You can insert UIButtons into UITableViewCells. Those UIButtons won't conflict with the UITableViewCells tap gesture. I would subclass UIButton so you could pass that row and item data to that button when created
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"%ld",(long)indexPath.row);
if (indexPath.row==0)
{
[self performSegueWithIdentifier:#"abc" sender:self];
}
if (indexPath.row==1)
{
}
}

Can I use both UITableViewCellEditingStyleInsert and UITableViewCellEditingStyleDelete two button together?

I return canEditRowAtIndexPath is YES. If I swipe left, I can see the delete button and implement my delete action. How can I do if I swipe left, both insert button and delete button appear together?
I know there is a way, I should have a custom cell with two button on the right and just add a panGesture to recognize the swipe action. But I want to use Apple provide for us to do such easy work. Just can see insert and delete button together when I swipe the cell left? My apology for my poor expression.
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(editingStyle==UITableViewCellEditingStyleInsert)
{
NSLog(#"click insert");//I only have delete button, I also want to have insert button .
}
if(editingStyle==UITableViewCellEditingStyleDelete)
{
NSLog(#"click delete");
}
}
I know tableView:editActionsForRowAtIndexPath can do this job … But it is provide for IOS8.0 and later,,How to do for IOS7
At least as of iOS 8 this can't be done (I don't know if this changed in iOS 9). A cell can only have one of the 3 possible editing styles - None, Insert, or Delete. UITableViewCell does not support both Insert and Delete at the same time. When the table is in editing mode, the cell will show either no button, an insert icon on the left, or the delete icon on the left based on the row's single editing style.
It actually makes no sense to have both insert and delete on the same row. What does that mean for the user? Normally a table view would only have a single row (per section) that might have the insert editing style. This row, when tapped, allows the user to add a new row to the table view. Other existing rows might have the delete editing style to allow the user to delete that specific row.
So again, what would it mean for a single row to have both insert and delete editing styles?

Assign different buttons, with different behaviours for different columns

In my project I've got UITableView.
I need to assign different buttons, with different behaviours for different columns.
Question:
Where is the correct way to set different behaviours & actions for buttons? Is it in (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath?
How is the correct way to assign different buttons with different behaviours to different columns? I am thinking about [_buttonArray objectAtIndex:indexPath.section]; is it the right way?
Example: Column 1 - Button A -> after button A pressed change button.title and size and do X.
You should use the below method for button behaviors if you want the user to be able to hit the entire cell and have the button action fire. If not, you should use an action delegate in your custom cell class. Let me know if you need help setting up the protocols file and or delegate method.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}

How can I make a view with TabGestureReganizer in a UITableViewCell able to respond?

In my custom UITableViewCell there's an ImageView which is able to be clicked and do an action.
But when I try to implements it, I find lots of problems.
1.When I click the Cell, the cell is clicked and highlighting, but my imageView's action is never shown.(I guess that the cell responded my touch before my imageView did)
2.When I add a button to the cell, the cell will respond the button event first and I wonder why?
3.I was told to use method (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath to implement it, but if i has not only one this imageView in my cell, how can I implement?
isUserInteractionEnabled defaults to NO for UIImageView. And for good reason --- you'd typically use a button with a background image for this. But what you're doing should work if you set isUserInteractionEnabled to YES.

Moving Delete icon on UITableView in 'grouped' style into the cell?

I have a UITableView style set to grouped. This works correctly except when in edit mode the 'minus' icon for Deleting a cell isn't within the cell. It's to the left. In the Weather App that icon is in the cell. Anyone know how to fix this?
Image here:
I know this is an old post, but I had a hard time finding the solution to this, so I figured I'd post it:
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
This is normal. It looks like Weather uses a plain table view with its corners rounded, not a grouped table view. But I'd you mist have this behavior, try changing the size of the cell's background view when it's editing...

Resources