Open Radunani opened 7 years ago
I have the exact same question... any luck with it?
i did not find any solution and just did in other way..
@Radunani Share it 👍
in my case i just add a button in each cell when is in edit mode, and that button have the same action like my second button in swipe, i find a solution just to show to user he can swipe it
you can try it in did select or when tableview going to edit mode
// UITableViewCell *cell = [_customWorkoutsTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
//
// __block UILabel *swipeLabel = [[UILabel alloc]initWithFrame:CGRectMake(cell.bounds.size.width,
// 0,
// 200,
// cell.bounds.size.height)];
//
// swipeLabel.text = @" Swipe Me";
// swipeLabel.backgroundColor = [UIColor greenColor];
// swipeLabel.textColor = [UIColor blackColor];
// [cell addSubview:swipeLabel];
//
// [UIView animateWithDuration:0.3 animations:^{
// [cell setFrame:CGRectMake(cell.frame.origin.x - 100, cell.frame.origin.y, cell.bounds.size.width, cell.bounds.size.height)];
// } completion:^(BOOL finished) {
// [UIView animateWithDuration:0.3 animations:^{
// [cell setFrame:CGRectMake(cell.frame.origin.x + 100, cell.frame.origin.y, cell.bounds.size.width, cell.bounds.size.height)];
// } completion:^(BOOL finished) {
// [swipeLabel removeFromSuperview];
// swipeLabel = nil;
// }];
Check this methods, you can use them to swipe programmatically, show hints, etc:
/** Utility methods to show or hide swipe buttons programmatically */
-(void) hideSwipeAnimated: (BOOL) animated;
-(void) hideSwipeAnimated: (BOOL) animated completion:(nullable void(^)(BOOL finished)) completion;
-(void) showSwipe: (MGSwipeDirection) direction animated: (BOOL) animated;
-(void) showSwipe: (MGSwipeDirection) direction animated: (BOOL) animated completion:(nullable void(^)(BOOL finished)) completion;
-(void) setSwipeOffset:(CGFloat)offset animated: (BOOL) animated completion:(nullable void(^)(BOOL finished)) completion;
-(void) setSwipeOffset:(CGFloat)offset animation: (nullable MGSwipeAnimation *) animation completion:(nullable void(^)(BOOL finished)) completion;
-(void) expandSwipe: (MGSwipeDirection) direction animated: (BOOL) animated;
Sure, you can do that. This was my main reason for switching from the default iOS implementation to MGSwipeTableCell.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
MGSwipeTableCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if(cell) {
[cell showSwipe:MGSwipeDirectionRightToLeft animated:YES];
}
}
Hope that helps!
Swift example:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as! MGSwipeTableCell
cell.showSwipe(.rightToLeft, animated: true)
}
Make sure you set the delegate of the cell or else it won't trigger
Here is one way, by updating table view for the specific cell:
self.tableView.reloadRows(at: [indexPath], with: .right)
i just want to know if i can programmatically swipe cell at index or multiple cells, some users dont know about hidden menu there, thanks