我有一个包含多个标签的自定义单元格的 TableView。我在其中一个标签上添加了一个 Tapgesture,因此会出现一个弹出窗口。问题是,弹出窗口没有出现在它应该出现的位置(居中并位于标签顶部)。
这条线有什么问题:
[self.popupMenu showInView:self.view atPoint:CGPointMake(label.center.x, label.frame.origin.y)];
表视图.m:
- (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;
}
点击手势的方法:
- (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 << CurrentOrder[indexPath.row] << std::endl;
UILabel *label = (UILabel *)cell.customAmountLabel;
[self.popupMenu showInView:self.view atPoint:CGPointMake(label.center.x, label.frame.origin.y)];
}
}