搶斷觸摸我有類似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