开发者

call to method every time when button is clicked at each cell

i have an customized cell that is loaded in table view cell and each cell have button with tag value. I need to call the IBAction method at each indexpath.row. For example if first row have that button than call should be made from first row to that action. Actualy i want to copy some text from each row when button is clicked and post it to Facebook. here is my code:

- (UITableViewCell *)tableView:(UITableView *)tableView
  cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static开发者_高级运维 NSString *CellIdentifier = @"cell1";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
  if (cell == nil) 
  { 
      [[NSBundle mainBundle] loadNibNamed:@"audioviewcell" owner:self options:NULL];
      cell = nibloadedcell;
    }
fbbutton = (UIButton*) [cell viewWithTag:7]; 
  if(fbbutton)
  {
      [self facebookclick:(id)];
     }


  return cell;
}
-(IBAction)facebookclick:(id)sender
{

  }

i am unable to configure this.


see if this helps,

[cell.fbbutton addTarget:self action:@selector(facebookclick:) forControlEvents:UIControlEventTouchDown];   

-(IBAction)facebookclick:(id)sender
{
    UITableViewCell *clicked = (UITableViewCell *)[[sender superview] superview];
    // do your things with your cell here.
    NSIndexPath *clickedPath = [self.tableView indexPathForCell:clicked];
    // do your things with your index path here.
}


The method cellForRowAtIndexPath: will only return a cell. Try calling your action in the UITableViewDelegate method didSelectRowAtIndexPath: instead. This is what's called when a cell is selected.


 [cell.fbbutton addTarget:self action:@selector(facebookclick:) forControlEvents:UIControlTouchUpInside];

  -(IBAction)facebookclick:(id)sender
        {
          button1 = (UIButton *)sender;
          // By this u got ur whole cell here...
         UITableViewCell *cell = (UITableViewCell*)[button superview];
         int row = [tblView indexPathForCell:cell].row;

        }

You can also assign button`s tag and get content of particular row of your array...

By

button1 = (UIButton *)sender;
 int row = button1.tag;

Hope This is useful to you...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜