检测点击TableView单元格

时间:2014-05-05 10:29:34

标签: ios objective-c ios7 cocos2d-iphone

我使用CCTableView创建一个以CCNode为单位的表格。那些CCNode每个都有一个按钮。我希望能够检测用户是否点击了一个单元格,以及是否点击了该按钮。但是CCTableView没有tableView:didSelectRowAtIndexPath:方法,所以我该怎么办呢?你知道有这种方法的任何开源类吗?

P.S。我使用的是cocos2d的第3版

2 个答案:

答案 0 :(得分:0)

我在尝试了很多事情之后采取了不同的方法

@interface WKTableCell : CCTableViewCell
@end

@implementation WKTableCell
- (instancetype) initWithTitle: (NSString *) title
{
    self = [super init];
    if (!self)
        return nil;
      [self.button setTitle:title];
      // This is a transparent png (400x200) for my needs
      CCSpriteFrame * frame = [CCSpriteFrame frameWithImageNamed:@"cell.png"] ;

      [self.button setPreferredSize:CGSizeMake(frame.originalSize.width, frame.originalSize.height)];
      [self.button setContentSizeType:CCSizeTypePoints];
      [self.button setBackgroundSpriteFrame:frame forState:CCControlStateNormal];
}
// then in your table

[table setBlock:^(id sender) {
    CCLOG(@"yup, this gets called.. ");
}];

这对我有用..

答案 1 :(得分:-1)

您的CCTableView会响应CCTouchDelegate,因此您可以使用ccTouchBegan等 检测点然后计算那个点上的那个单元格。这里的课程参考:

http://docs.huihoo.com/doxygen/cocos2d-x/2.1.2/d0/d38/classcocos2d_1_1_c_c_touch_delegate.html

相关问题