我一直在尝试设置一个 UIScrollView
在定制内 UITableViewCell
.我试过添加 UIScrollView
自定义内.xib
文件,将其子类化并手动将其作为 subview 添加到 UITableViewCell
在cellForRowAtIndexPath
方法。在所有这些中,我设置了 contentSize
的 UIScrollView
在 cellForRowAtIndexPath
内.但是无论采用哪种方法,我都无法使其水平滚动。这里有一些代码可以给你一个想法。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"Custom_Cell";
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
CellIdentifier = @"Custom_Cell";
}
CustomCell *cell = (CustomCell *)[self.fpTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:nil options:nil];
// cell = [nib objectAtIndex:0];
for(id currentObject in nib)
{
if([currentObject isKindOfClass:[CustomCell class]])
{
cell = (CustomCell *)currentObject;
break;
}
}
cell.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
[cell.pgCellScroll setContentSize:CGSizeMake(160*3 + (5*4), 160)];
[cell.pgCellScroll setScrollEnabled:YES];
[cell.pgCellScroll setDelaysContentTouches:YES];
[cell.pgCellScroll setCanCancelContentTouches:NO];
}
知道我哪里出错了吗?感谢您的帮助。
最佳答案
为 TableView 和其中的 ScrollView 分配一个委托(delegate),并在这些委托(delegate)中实现gestureRecognizer:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer
*)otherGestureRecognizer {
return YES; }
关于ios - UITableViewCell 内的 UIScrollView - 水平滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20198550/