Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Second Edit:</p> <p>This was copied from an answer above:</p> <p>inside the <code>-cellForRowAtIndexPath:</code> method:</p> <pre><code> if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellSubtitle]; UIButton *market = [UIButton buttonWithType:UIButtonTypeCustom]; [market setFrame:CGRectMake(200, 6, 30, 30)]; [market addTarget:self action:@selector(marketPressedAction:) forControlEvents:UIControlEventTouchDown]; [cell.contentView addSubview:market]; //Add all your UILabel INITIATION stuff here as well } UIButton *marketButton; for (UIView *subview in cell.subviews) { if ([subview isKindOfClass:[UIButton class]]) { marketButton = (UIButton *)subview; break; } } marketButton.tag = [indexPath row]; UILabel *priceLabel = [cell.contentView viewWithTag:3000]; UILabel *uploadTimeLabel = [cell.contentView viewWithTag:2000]; //Set up your labels and button now return cell; } EDIT: Leaving my original answer below for posterity but I see that you are setting the table index row as the MarketButton's tag. If you're using that to figure out which dataSource object to query, this is bad practice. You should be making a custom cell which can hold a reference to the object in your data source, so you don't have to ask the button for its tag, and then ask the data source array for the object at index:tag. </code></pre> <p>The reason this is bad is because somewhere, the state of your array could change, but the table cell is still displayed and still holds a tag pointing at the wrong index. If you just have the cell keep track of the object in question, no matter what happens to the array structure you're guaranteed to be modifying the object you need to.</p> <p>The only thing I would change about Firo's answer is to just add a "tag" property to each view in the cell, so you don't have to iterate each time you want to find it.</p> <p>Also took out the <code>[[UIButton alloc]init]</code> line because it's superfluous and might be considered a dangling pointer.</p> <pre><code>if (cell == nil) { // Everything that does not change should go in here! cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; UIButton *market = [UIButton buttonWithType:UIButtonTypeCustom]; [market setFrame:CGRectMake(200, 6, 30, 30)]; [market addTarget:self action:@selector(marketPressedAction:) forControlEvents:UIControlEventTouchDown]; market.tag = 9999; [cell.contentView addSubview:market]; } //don't have to do UIView iteration here UIButton *marketButton = [cell.contentView viewWithTag:9999]; </code></pre>
 

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