У меня есть TableView с пользовательскими ячейками, содержащими несколько ярлыков. Я добавил ссылку на одну из этих ярлыков, чтобы появилось всплывающее окно. Проблема в том, что всплывающее окно не появляется там, где оно должно быть (в центре и над меткой).popup using tapgesture на TableViewCell
Что случилось с линией:
[self.popupMenu showInView:self.view atPoint:CGPointMake(label.center.x, label.frame.origin.y)];
tableview.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)];
}
}
Переменная ячейки может стать нулем. вам лучше сделать процедуру проверки. –