我正在尝试设置 UIPageControl 并需要设置 currentPage
;我有以下内容,但一旦分配了值 self.pageControl.currentPage,它始终等于 0,即使它应该是正确的值。这是我第一次使用 UIPageControl,我认为我错过了一些非常基本的东西;可能总是在某个地方重置为 0。提前谢谢
这是我的代码
- (void)scrollViewDidEndDecelerating:(UIScrollView *)aScrollView
{
self.pageControl.currentPage = (int) floor((self.scrollView.contentOffset.x + 0.25)/320.0f);
int this_page=(int)(self.scrollView.contentOffset.x + 0.25)/320.0f;
self.pageControl.currentPage=this_page;
NSLog(@"here is property %d", self.pageControl.currentPage);
NSLog(@"here is this_page %d", this_page);
self.pageControl.currentPage=4;
NSLog(@"here is property after manual set %d", self.pageControl.currentPage);
}
和我的 NSLog 输出。
2013-03-03 10:19:14.204 Lt[32045:11303] here is property 0
2013-03-03 10:19:14.206 Lt[32045:11303] here is this_page 1
2013-03-03 10:28:03.993 Lt[32209:11303] here is property after manual set 0
2013-03-03 10:19:15.449 Lt[32045:11303] here is property 0
2013-03-03 10:19:15.449 Lt[32045:11303] here is this_page 2
2013-03-03 10:28:03.993 Lt[32209:11303] here is property after manual set 0
最佳答案
很可能self.pageControl
为零,即您从未正确连接 socket 。否则页面控件本身配置不正确,例如您从未设置numberOfPages
。
顺便说一句,在 iOS 6 中协调页面控件与分页 ScrollView 的最简单方法是使用 UIPageViewController。
关于ios - UIScrollView 和问题设置 UIPageControl 的当前页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15189088/