1
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.

chsab420
  • 191
  • 2
  • 3
  • 14

1 Answers1

1

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.

HTH,

Akshay

Akshay
  • 5,747
  • 3
  • 23
  • 35
  • I don't think you need to detect touches on your cell like this. If you have multiple subviews in your custom cell, you should be adding targets to them, using `addTarget:action:forControlEvents`. You have still not pasted the crash log. Does the multiple selection work after my suggestion? – Akshay Aug 23 '11 at 07:20
  • actually crash logs are nothing but when you touch two rows at the same time, Navigation controller gives error that you cant push two at one time. – chsab420 Aug 23 '11 at 08:11
  • Are you touching 2 rows simultaneously using 2 fingers? If yes, then this crash is occurring because of your custom touch detection. If you rely on the default table view detection, this crash won't occur. – Akshay Aug 23 '11 at 09:23
  • but i need custom cell touch as well. how can i solve this issue ? – chsab420 Aug 23 '11 at 11:12
  • Can you elaborate why you need custom cell touch? I am under the impression that you must be having multiple subcomponents in the cell, such as buttons, images, etc., tapping on which should cause something. If I am correct, then you do not need custom cell touch. – Akshay Aug 24 '11 at 09:11
  • i want to change cell image background on touch start and touch end. so i dont know anyother way how to do this. can you please guide me in this. thanks – chsab420 Aug 24 '11 at 10:33
  • By touch-start & touch-end, do you mean a finger is being dragged? Horizontally or vertically? – Akshay Aug 24 '11 at 11:06
  • no not necessarily dragged but just i want to detect if the finger has touched the cell so that i could change image. draging i dont need neither its direction. – chsab420 Aug 24 '11 at 11:24
  • @Akshay let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/2801/discussion-between-chsab420-and-akshay) – chsab420 Aug 24 '11 at 11:24