When UIButton button is clicked in UITableView clicks on several buttons

When I select one button in mine UItableView, the other buttons from bottom to bottom are also pressed. I use the target action on the button in the user view of the table and change the name of the sender in the method. Why does this single click select several UIButtons? Any help / suggestions would be greatly appreciated.

EDIT: I am using a partitioned lookup table

Here is my code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    PostTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

    // Configure the cell...
    [cell.likeButton addTarget:self action:@selector(likeButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    cell.likeButton.tag = indexPath.section;
    return cell;
}

-(void)likeButtonPressed:(UIButton *)sender {
    NSLog(@"%d",sender.tag);
    [sender setTitle:@"Pressed" forState:UIControlStateNormal];
}
+4
source share
3 answers

In your PostTableViewCell.h define a delegate

@protocol HandleCellInteractionDelegate <NSObject>
-(void) didPressButton:(NSString*)action forCell:(UITableViewCell *)theCell;
@end

In TableView.h, register as a delegate for this protocol.

<HandleCellInteractionDelegate>

In the tableview.m file add a delegate handler

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    // Create cell
    ....
    cell.delegate = self;
    if (self.qObjects current object selection state == selected)
        enable button
    else
        disable button
 }

  #pragma mark HandleCellInteractionDelegate

-(void) didPressButton:(NSString*)action forCell:(UITableViewCell *)theCell{
    // Now here you have access to your cell again. And you can update the cell button text as needed
    // Here save selection state in data model.. in self.qObjects <==
    cell.questionTextView.text = @"bla bla";

}
+1

uitableviewcell , init. , tableviewcontroller dequeueReusableCellWithIdentifier.

: // indexPath

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath   *)indexPath {

      PostTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

      // Configure the cell...
      cell.indexPath = indexPath;
      return cell;
   }

, :

  - (IBAction)buttonAction:(id)sender {

    NSLog(@"indexPath: %@", self.indexPath);
  }
0

, ,  cell.likeButton.tag = indexPath.row; cell.likeButton.tag = indexPath.section;

0

All Articles