Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are getting null because the view hierarchy in iOS 7 is changed.</p> <p>I recommend to use Delegate for getting the indexpath of TableViewCell.</p> <p><a href="http://ideamakerz.com/mzeeshanid/how-to-get-the-index-for-the-cell-when-you-click-a-button-in-the-cell/">You can get the sample project from here</a></p> <p>Here is the sample:</p> <p>My View Controller looks like this:</p> <p><pre><code> //#import "ViewController.h" //#import "MyCustomCell.h" @interface ViewController () { IBOutlet UITableView *myTableView; NSMutableArray *dataSourceArray; } @end @implementation ViewController -(void)viewDidLoad { [super viewDidLoad]; dataSourceArray = [[NSMutableArray alloc] init]; for(int i=0;i&lt;20;i++) [dataSourceArray addObject:[NSString stringWithFormat:@"Dummy-%d",i]]; } -(void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } //pragma mark - UITableView Delegate And Datasource - -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return dataSourceArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdenfifier = @"MyCustomCell"; MyCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdenfifier forIndexPath:indexPath]; [cell setDelegate:self]; [cell.myButton setTitle:[dataSourceArray objectAtIndex:indexPath.row] forState:UIControlStateNormal]; return cell; } //pragma mark - MyCustomCell Delegate - -(IBAction)myCustomCellButtonTapped:(UITableViewCell *)cell button:(UIButton *)sender { NSIndexPath *indexPath = [myTableView indexPathForCell:cell]; NSLog(@"indexpath: %@",indexPath); } @end</pre></code></p> <p>MyCustomCell.h looks like this:</p> <p><pre><code> //#import @protocol MyCustomCellDelegate @optional - (IBAction)myCustomCellButtonTapped:(UITableViewCell *)cell button:(UIButton *)sender; @end @interface MyCustomCell : UITableViewCell @property (weak, nonatomic) IBOutlet UIButton *myButton; @property(nonatomic, weak)id delegate; @end</pre></code></p> <p>MyCustomCell.m looks like this:</p> <p><pre><code> //#import "MyCustomCell.h" @implementation MyCustomCell -(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { } return self; } -(void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } //#pragma mark - My IBActions - -(IBAction)myCustomCellButtonTapped:(UIButton *)sender { if([self.delegate respondsToSelector:@selector(myCustomCellButtonTapped:button:)]) [self.delegate myCustomCellButtonTapped:self button:sender]; } @end</pre></code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload