有可能使用UIPageControl来控制UITableView的移动吗?
从苹果示例“PageControl”中,我们可以知道UIPageControl可以用来控制滚动视图中页面的移动。
由于UITableView是UIScrollView的子类,我想使用UIPageControl来控制表视图单元格的移动,就像在“PageControl”中一样。
但是找不到代理的任何接口。
问题是:
这是可能的吗? 为什么?
谢谢
让我回答我的问题:
以编程方式select和滚动
清单6-5以编程方式select一行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath { NSIndexPath *scrollIndexPath; if (newIndexPath.row + 20 < [timeZoneNames count]) { scrollIndexPath = [NSIndexPath indexPathForRow:newIndexPath.row+20 inSection:newIndexPath.section]; } else { scrollIndexPath = [NSIndexPath indexPathForRow:newIndexPath.row-20 inSection:newIndexPath.section]; } [theTableView selectRowAtIndexPath:scrollIndexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle]; }
这当然是可能的,但你为什么要这样? 一个表视图垂直滚动,而一个页面控件有一个水平的布局,所以它可能会看起来/感觉怪异。
无论如何,如果你真的想这样做,添加您的视图控制器作为页面控制的目标:
[pageControl addTarget:self action:@selector(pageChanged:) forControlEvents:UIControlEventValueChanged];
然后在动作中实现滚动:
- (void)pageChanged:(UIPageControl *)sender { float scrollPosition = ((float)sender.currentPage / (float)sender.numberOfPages) * tableView.contentSize.height; [tableView scrollRectToVisible:CGRectMake(0, scrollPosition, 1, 1) animated:YES]; }
- 不调用glkView drawInRect
- xcode 5中的Shell脚本调用错误
- NSManagedObject值是正确的,然后在将更改从父NSManagedObjectContext合并到子NSManagedObjectContext时不正确
- 用导航呈现自定义大小的视图控制器
- Swift – 为什么init(编码器)在AFHTTPSessionManager中是必需的?
- 如何通过货币代码设置iOS NSNumberFormatter区域设置?
- 我使用Swift创建了Affirm裸露骨骼骨架应用程序
- 将UIImage转换为Keras模型的MLMultiArray
- 带有inputAccessoryView的UIViewController不会被释放