forum

Home / DeveloperSection / Forums / iOS How to get button text from tableview cell

iOS How to get button text from tableview cell

Anonymous User187323-Jul-2015

I am using simple tableview and i have add button in every cell , The Problem is how to get button text from cell number second and any other cell number get button text i am using this code but its not working

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];

UITableViewCell *cell = [tbl_view cellForRowAtIndexPath:indexPath]; 

for( UITableViewCell *getview in cell.subviews)

{

       if([getview isKindOfClass:[UIButton class]])

        {

             NSLog(@"sdfsdfsd");

             // UIButton *button = (UIButton *);

        }

}

This code is set button in tableview cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:

(NSIndexPath *)indexPath{ 

 

      static NSString *simpleTableIdentifier = @"SimpleTableItem";

      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:

simpleTableIdentifier];

      UILabel *fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 5, 250,20)];

      if (cell == nil) { 

          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:

simpleTableIdentifier];

         cell = [[UITableViewCell alloc] init];

      } 

      cell.backgroundColor=[UIColor clearColor];

    UIButton *button_chaeckbox = [UIButton buttonWithType:UIButtonTypeCustom];

      button_chaeckbox.backgroundColor=[UIColor clearColor];

      button_chaeckbox.frame = CGRectMake(10, 10, 15, 15);

 

      if( [checkedArray containsObject:[NSString stringWithFormat:@"%ld",(long)indexPath.row]])

      {

          [button_chaeckbox setBackgroundImage:[UIImage imageNamed:

@"checked_checkbox.png"] forState:UIControlStateNormal];

      }else{

         [button_chaeckbox setBackgroundImage:[UIImage imageNamed:

@"empty_bob.png"] forState:UIControlStateNormal];

      }

 [button_chaeckbox setTitle:@"creaButtonname" forState:UIControlStateNormal];

      button_chaeckbox.tag=indexPath.row;

      [button_chaeckbox addTarget:self action:@selector(checkboxAction:)

      forControlEvents:UIControlEventTouchUpInside];

      [cell addSubview:button_chaeckbox];

}

Please give me solution , i have try this code in ios 7 and ios 8 this is not working.


Updated on 23-Jul-2015
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By