我有一個TableView,其中包含含有多個標籤的自定義單元格。我在這些標籤中的一個上添加了一個tapgesture,這樣彈出窗口就會出現。問題是,彈出窗口不會出現在應該出現的位置(居中且位於標籤頂部)。在TableViewCell上使用Tapgesture彈出框
這有什麼錯行:
[self.popupMenu showInView:self.view atPoint:CGPointMake(label.center.x, label.frame.origin.y)];
tableview.m:
- (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)];
}
}
單元格變量可能成爲零。你最好做一個檢查程序。 – 2013-02-26 10:57:17