Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // in .h
- #import <UIKit/UIKit.h>
- #import "PullRefreshTableViewController.h"
- #import "DetalleMailViewController.h"
- //my class is "MensajesTableViewController" as delegate of "DetalleMailViewController"
- //the view I want to show when a row is tapped.
- @interface MensajesTableViewController : PullRefreshTableViewController <DetalleMailViewControllerDelegate>
- @property (nonatomic, strong) NSMutableArray *mailAuthors;
- @property (nonatomic) int row_tabla_delete;
- - (IBAction)presentMenu:(id)sender;
- @end
- //in .m make the synthesize of mailAuthors and some relevant code:
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.tableView.allowsSelection = YES;
- //This gesture works fine
- UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
- initWithTarget:self action:@selector(presentMenu:)];
- lpgr.minimumPressDuration = 0.5; //seconds
- lpgr.numberOfTouchesRequired =1;
- lpgr.delegate = self;
- [self.tableView addGestureRecognizer:lpgr];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *idCell = @"mailTableCell";
- MailCell *celda = [tableView dequeueReusableCellWithIdentifier:idCell];
- if(celda == nil){
- celda = [[MailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idCell];
- }
- //@property (nonatomic, strong) NSMutableArray *mailAuthors; in .h
- //The data for "mailAuthors" is loaded in other part, and showed ok in the tableview in the simulator for every row.
- celda.mailAuthor.text = [self.mailAuthors objectAtIndex:[indexPath row]];
- return celda;
- }
- -(void) viewWillAppear:(BOOL)animated{
- [[self tableView] reloadData];
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- //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...
- NSLog(@"tapped %d", [indexPath row]);
- }
- - (IBAction)presentMenu:(id)sender {
- if ([sender state] == UIGestureRecognizerStateBegan){
- CGPoint p = [sender locationInView:self.tableView];
- NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:p];
- if (indexPath != nil){
- self.row_tabla_delete = [indexPath row];
- }
- //some code to delete the row
- }
- }
Add Comment
Please, Sign In to add comment