Note that there are some explanatory texts on larger screens.

plurals
  1. POpopup using tapgesture on a TableViewCell
    primarykey
    data
    text
    <p>I have a TableView with custom cells containing multiple labels. I added a tapgesture on one of these labels so a popup will appear. The problem is, the popup doesn't appear where it should be (centered and on top of the label).</p> <p>What's wrong with the line:</p> <pre><code>[self.popupMenu showInView:self.view atPoint:CGPointMake(label.center.x, label.frame.origin.y)]; </code></pre> <p>tableview.m:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // add a tap gesture recognizer UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap:)]; [cell.customAmountLabel addGestureRecognizer:tapGesture]; NSString *ItemName = [NSString stringWithCString:CurrentOrder[indexPath.row].c_str() encoding:NSUTF8StringEncoding]; NSString *ItemAmount = [NSString stringWithCString:CurrentOrder[indexPath.row].c_str() encoding:NSUTF8StringEncoding]; cell.customNameLabel.text = ItemName; cell.customAmountLabel.text = ItemAmount; return cell; } </code></pre> <p>method for tap gesture:</p> <pre><code>- (void)labelTap:(UITapGestureRecognizer *)gestureRecognizer { // get location of the swipe CGPoint location = [gestureRecognizer locationInView:self.tableCurrentOrder]; // get the corresponding index path within the table view NSIndexPath *indexPath = [self.tableCurrentOrder indexPathForRowAtPoint:location]; // check if index path is valid if(indexPath) { // get the cell out of the table view CustomCell *cell = (CustomCell *) [self.tableCurrentOrder cellForRowAtIndexPath:indexPath]; // update the cell or model std::cout &lt;&lt; CurrentOrder[indexPath.row] &lt;&lt; std::endl; UILabel *label = (UILabel *)cell.customAmountLabel; [self.popupMenu showInView:self.view atPoint:CGPointMake(label.center.x, label.frame.origin.y)]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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