iphone - didSelectRowAtIndexPath:仅在长按自定义单元格后才被调用 [英] iphone - didSelectRowAtIndexPath: only being called after long press on custom cell

查看:86
本文介绍了iphone - didSelectRowAtIndexPath:仅在长按自定义单元格后才被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个基于表视图的应用程序。我为表创建了一个自定义表格单元格,其中包含2个标签,1个图像和1个按钮。表视图数据源方法正常工作。我在自定义单元格和视图控制器类中使用xib,并将委托和数据源连接到文件的所有者。但问题是当我选择表格行时,didSelectRowAtIndexPath没有起火。如上所述,解雇它的唯一方法是按住电池约3-4秒。有没有人知道为什么会发生这种情况?

I am creating one table view based application. I have created a custom table cell for table, that contains 2 labels, 1 image and 1 button. The table view Data source method is working properly. I am using xib for both custom cell and view controller class and i connect delegate and data source to the file's owner. But the problem is when i select the table row, didSelectRowAtIndexPath is not getting fire. As mentioned the only way to fire it is to hold down on the cell for about 3-4 seconds. Does anyone have any idea why this is happening?

感谢您的任何指示...

Thanks for any pointers...

这是我的表视图方法..

Here is my table view methods..

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [finalAddonsArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    NewCustomCell *cell = (NewCustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"NewCustomCell" owner:self options:nil];
        cell=[nib objectAtIndex:0];
    }

    Addons *addons1=[[Addons alloc]init];
    addons1= [finalAddonsArray objectAtIndex:indexPath.row];

    if (addons1.data == nil) {
        cell.ivCategory.image = [UIImage imageNamed:@"blogo.jpg"];
    }
    else
    {
        cell.ivCategory.image=[UIImage imageWithData:addons1.data];
    }

    cell.lblTitle.text = addons1.name;
    if (addons1.price == nil) {
        cell.lblPrice.text = nil;
    }
    else{
        cell.lblPrice.text = [NSString stringWithFormat:@"%@ rs",addons1.price];
    }
    [cell.button addTarget:self
                    action:@selector(editButtonPressed:)
          forControlEvents:UIControlEventTouchUpInside];

    cell.button.tag=indexPath.row;
    index = indexPath;
    cell.selectionStyle = UITableViewCellSelectionStyleGray;

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"sjcjksbcjksbcfkebscf1234567890");
}

如果我使用默认的UITableViewCell而不是自定义,我还会得到一件事单元格然后我的问题也一样,委托方法没有起火。

One more thing i am getting that if i am using default UITableViewCell instead of custom cell then also my problem is same, delegate method is not getting fire.

自定义单元格属性:

< img src =https://i.stack.imgur.com/PREPB.pngalt =在此处输入图像说明>

推荐答案

同样的问题发生在我身上,因为我在其上添加了一个水龙头手势识别器。
如果您使用过任何手势识别器,请尝试将其删除并检查是否会导致问题。

same problem happened with me because I have added a tap gesture recogniser over it. If you have used any gesture recognizer try removing it and check if it causing the problem.

编辑:解决方案由Ali评论:
如果您使用了点击手势,可以使用 [点击setCancelsTouchesInView:NO];

Solution as commented by the Ali: If you have used tap gesture you can use [tap setCancelsTouchesInView:NO];

这篇关于iphone - didSelectRowAtIndexPath:仅在长按自定义单元格后才被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆