抢断触摸我有类似this one问题,但答案只要没有太大的帮助。 我UITableView
一些定制UITableViewCells
,这些细胞有一定的嵌套自定义UIViews
最后一些UIButtons内。正如上面指出的那样,问题在于当我触摸我的按钮时,触摸事件不会填充到UITableView
,并且它从不滚动。的UIButton内的UITableViewCell从UITableView中
下面是一些代码(这只是最快的方式重现,这不是我的实际代码):
@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView * tableView;
@end
@implementation ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0,
self.view.bounds.size.width,
self.view.bounds.size.height)
style:UITableViewStylePlain];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [[UITableViewCell alloc] init];
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = [UIColor redColor];
button.frame = CGRectMake(0, 0, 50, 44);
[cell.contentView addSubview:button];
return cell;
}
@end
中唯一的单元格红色按钮不会让表视图反弹滚动。
谁能帮我一点吗?
P.S.不要关注我提供的代码的愚蠢,我意识到所有关于它的问题。我只是提供它来显示问题的全部内容。这是buttonView
和scrollView
的冲突。
我仍然无法得到这个'UITontrol'在'UITableView'里面工作。此外,因为'UITableView'是'UIScrollView'的子类,所以你的代码应该是'self.tableView.canCancelContentTouches = YES;' – johnboiles
@johnboiles你应该设置elf.tableView.scrollView.delaysContentTouches = NO; – passol
答案中显示的组合不起作用。 @johnboiles是正确的。刚刚为我工作的是:mytable.delaysContentTouches = false和mytable.canCancelContentTouches = true。这使得我的细胞内的按钮就像平常一样工作。 – zumzum