【问题标题】:UITableViewCell select doesn't working in objective cUITableViewCell 选择在目标 c 中不起作用
【发布时间】:2019-01-15 11:48:12
【问题描述】:

我是 Objective C 的新手,在使用自定义 UITableViewCell 时遇到问题。

我在自定义 tableviewcell 中使用 touchesBegan,如下所示:

#import "UserListTableViewCell.h"

@implementation UserListTableViewCell

@synthesize userTableViewCellView, cellIndex;

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
           ... .. ...
}

-(void) touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
            ... ... ...
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
            ... ... ...
}

然后我不能使用函数 didSelectRowAtIndexPath{}。 即使使用 touchesBegan 方法,我如何使用 TableView 选择。

如果你能解决这个问题,请提前告诉我。

谢谢。

【问题讨论】:

  • 你想对touchesBegan事件做一些额外的事情吗?我认为你可以通过使用didSelectRowAtIndexPath() 轻松实现任何你想要的。
  • 感谢您的回复。我的意思是 didSelectRowAtIndexPath() 不起作用。有预付款吗?

标签: ios objective-c uitableview


【解决方案1】:

如果在使用 touchesBegan 后 didSelectRowAtIndexPath() 无法正常工作,您可能需要检查您的自定义单元格方法中是否有 [super touchesBegan]。像这样:

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
           [super touchesBegan:touches withEvent:event];

           ... .. ...
}

.....

希望对你有帮助!

【讨论】:

    【解决方案2】:

    出现这种情况是因为方法

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    }
    

    捕获事件,但不会将它们进一步发送到响应者链。正如上面提到的@Daniel,如果您像这样添加对super 的调用:

    [super touchesBegan:touches withEvent:event];
    

    事件将进一步发送到- (void)didSelectRowAtIndexPath 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-24
      • 1970-01-01
      相关资源
      最近更新 更多