chsab420
chsab420

Reputation: 191

Multi Touch problem in Custom UiTableViewCell

static NSString *cellIdentifier = @"Cell";
AssignmentTableCell *cell = (AssignmentTableCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AssignmentTableCell" owner:self options:Nil];
    cell = [nib objectAtIndex:0];
}

Here is my Code for custom Cell initialization. I am detecting uitouch for custom cells and then i am pushing view controller rather than using DidSelected Event of the UItableView. But problem i am facing is

I can select 2 rows at a time, which is not my intension and that leads to application crash. I have tried to disable multitouch but of no use. they still keep selecting 2 cells at a time.

Any Help will be appreciated.

Edit 1:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    imgBg.image = [UIImage imageNamed:@"rowSelected.png"];
    [[self delegate] touchStarted:tag];
}

-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    imgBg.image = [UIImage imageNamed:@"7CustomCellBackground.png"];
    [[self delegate] touchEnded:tag];
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    //imgBg.image = [UIImage imageNamed:@"7CustomCellBackground.png"];
    [[self delegate] rowTocuchedFromClicked:tag];
}

Here are the touches method of the cell.

Upvotes: 1

Views: 1188

Answers (1)

Akshay
Akshay

Reputation: 5765

Can you add some code regarding how you are detecting touches on the cell? Also, the reason you are seeing multiple selections in because you are not de-selecting the selected cell. Do something like-

-(void) tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath)indexPath
{
    [tableView deselectRowAtIndexPath: indexPath animated: YES];
    //your other stuff
}

The reason for the crash is something else, which can only be ascertained after you paste the console logs.

Upvotes: 1

Related Questions