---
title: "iOS How to get button text from tableview cell"  
description: "iOS How to get button text from tableview cell"  
author: "Anonymous User"  
published: 2015-07-23  
updated: 2015-07-23  
canonical: https://www.mindstick.com/forum/23365/ios-how-to-get-button-text-from-tableview-cell  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# iOS How to get button text from tableview cell

I am using [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) tableview and i have [add](https://www.mindstick.com/forum/12983/add-address-in-textbox-when-page-is-load-and-if-i-search-address-in-textbox-show-in-map-by-javascript) [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) in every cell , The [Problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is how to get button [text](https://www.mindstick.com/blog/301635/did-people-reinvent-texting-to-express-the-full-range-of-emotions) from cell number [second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society) and any other cell number get button text i am using this [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) 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_box_b.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](https://www.mindstick.com/articles/12222/core-data-and-how-to-use-it-in-ios-objective-c) 7 and ios 8 this is not working.

## Replies

### Reply by Tarun Kumar

**Use this code for reuse cells in table view**

```
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:                                                        (NSIndexPath *)indexPath {     static NSString  *simpleTableIdentifier = @"SimpleTableItem";     UITableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:                                                                                  simpleTableIdentifier];     if (cell == nil) {          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault                                                                      reuseIdentifier:simpleTableIdentifier];         cell=[[UITableViewCell alloc] init];         UILabel  *fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 5, 250,20)];         cell.backgroundColor=[UIColor clearColor];         UIButton *button_chaeckbox = [UIButton buttonWithType:UIButtonTypeCustom];         button_chaeckbox.backgroundColor=[UIColor clearColor];         button_chaeckbox.frame = CGRectMake(10, 10, 15, 15);         [button_chaeckbox addTarget:self  action:@selector(checkboxAction:)         forControlEvents:UIControlEventTouchUpInside];         [cell addSubview:button_chaeckbox];         button_chaeckbox.tag=1001;     }     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_box_b.png"]                                                                              forState:UIControlStateNormal];     }}
```

**Use this code for get button from cell**

```
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];UITableViewCell *cell = [tbl_view cellForRowAtIndexPath:indexPath];UIButton *button_chaeckbox=(UIButton*)[cell viewWithtag:1001];
```


---

Original Source: https://www.mindstick.com/forum/23365/ios-how-to-get-button-text-from-tableview-cell

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
