3

事情就是这样。我有tableview一个可变数量的rows. 当您点击其中一个时,会显示详细视图。

如果您从 0 到 9、11 到 19、21 到 29 等点按行,一切都很好……但它不适用于行号10, 20, 30等……即使在此行上检测到长按,所以alert显示,以便在必要时删除该行(我可以毫无问题地删除它),但从didselectrowatindexpath不调用。

我认为这是tableview唯一10 rows同时保持的东西。但是cellForRowAtIndex对于所有行,一切都正常。我将所有数据保存在一些中NSMutableArray,以访问我需要的数据[indexPath row]

我已经花了一些时间寻找类似的帖子,但没有找到类似的东西。

任何帮助将不胜感激。谢谢!

一些代码:

//    in .h

#import <UIKit/UIKit.h>
#import "PullRefreshTableViewController.h"
#import "DetalleMailViewController.h"

@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];
    }

    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

    }
}

MailCell.h I have theUILabel for mailAuthor as a property, and linked in the storyboard with the UILabel inside theUITableViewCell . In the storyboard, I have aTableView Controller linked to my own class "MensajeTableViewController ", theUITableViewCell to my "MailCell`"中。如果有一些需要添加一些其他相关代码,或者别的什么,请帮帮我。

4

0 回答 0