Guest User

Untitled

a guest
Jan 21st, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. // in .h
  2.  
  3. #import <UIKit/UIKit.h>
  4. #import "PullRefreshTableViewController.h"
  5. #import "DetalleMailViewController.h"
  6.  
  7. //my class is "MensajesTableViewController" as delegate of "DetalleMailViewController"
  8. //the view I want to show when a row is tapped.
  9. @interface MensajesTableViewController : PullRefreshTableViewController <DetalleMailViewControllerDelegate>
  10.  
  11. @property (nonatomic, strong) NSMutableArray *mailAuthors;
  12. @property (nonatomic) int row_tabla_delete;
  13.  
  14. - (IBAction)presentMenu:(id)sender;
  15.  
  16. @end
  17.  
  18. //in .m make the synthesize of mailAuthors and some relevant code:
  19.  
  20.  
  21. - (void)viewDidLoad
  22. {
  23. [super viewDidLoad];
  24.  
  25. self.tableView.allowsSelection = YES;
  26. //This gesture works fine
  27. UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
  28. initWithTarget:self action:@selector(presentMenu:)];
  29. lpgr.minimumPressDuration = 0.5; //seconds
  30. lpgr.numberOfTouchesRequired =1;
  31. lpgr.delegate = self;
  32. [self.tableView addGestureRecognizer:lpgr];
  33. }
  34.  
  35. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  36. {
  37. static NSString *idCell = @"mailTableCell";
  38. MailCell *celda = [tableView dequeueReusableCellWithIdentifier:idCell];
  39. if(celda == nil){
  40. celda = [[MailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idCell];
  41. }
  42. //@property (nonatomic, strong) NSMutableArray *mailAuthors; in .h
  43. //The data for "mailAuthors" is loaded in other part, and showed ok in the tableview in the simulator for every row.
  44. celda.mailAuthor.text = [self.mailAuthors objectAtIndex:[indexPath row]];
  45. return celda;
  46. }
  47.  
  48. -(void) viewWillAppear:(BOOL)animated{
  49. [[self tableView] reloadData];
  50. }
  51.  
  52. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  53. {
  54. //I really use a segue here, but for the sake of simplicity, I just put a trace, never called for rows 10, 20, 30... The segue works fine the rest of the time...
  55. NSLog(@"tapped %d", [indexPath row]);
  56. }
  57.  
  58. - (IBAction)presentMenu:(id)sender {
  59.  
  60. if ([sender state] == UIGestureRecognizerStateBegan){
  61. CGPoint p = [sender locationInView:self.tableView];
  62.  
  63. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:p];
  64.  
  65. if (indexPath != nil){
  66. self.row_tabla_delete = [indexPath row];
  67. }
  68.  
  69. //some code to delete the row
  70.  
  71. }
  72. }
Add Comment
Please, Sign In to add comment