Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all there is no need to add the button each time a cell is displayed. You only have to add the subviews of the cell when you create a new cell. You'll get better scrolling performance this way.</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [self.horizontalTableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; // Add image button to cell UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(5, 5, 240, 240)]; // set tag so you can get the button later button.tag = 1021; [button addTarget:self action:@selector(photoButton:) forControlEvents:UIControlEventTouchUpInside] // more button config [cell.contentView addSubView:button]; } // get image button UIButton *button = [cell.contentView viewWithTag:1021]; // configure image button UIImage *image = [UIImage imageNamed:[contentArray_ objectAtIndex:indexPath.row]]; [button setImage:image forState:UIControlStateNormal]; return cell; } </code></pre> <p>Next you can use use superview on the button (= sender) to go back to the UITableViewCell. With the cell you can get the indexPath of that cell. </p> <pre><code>- (IBAction)photoButton:(id)sender { UIView *contentView = [sender superview]; UITableViewCell *cell = [contentView superview]; NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; } </code></pre>
    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.
 

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