Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
488 views
in Technique[技术] by (71.8m points)

ios - iphone - didSelectRowAtIndexPath: only being called after long press on custom cell

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");
}

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.

Custom cell properties:

enter image description here enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...