2013-03-03 27 views
0

我想設置一個UIPageControl並需要設置currentPage;我有以下但一旦賦值爲self.pageControl.currentPage,它總是等於0,即使它應該是一個正確的值。這是我第一次使用UIPageControl,我想我錯過了一些非常基本的東西;可能總是在某處重置爲0。 THX提前UIScrollView和問題設置UIPageControl的當前頁面

這裏是我的代碼

- (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 

回答

1

最有可能的self.pageControl是零,即你從來沒有正確地連接插座。否則頁面控制本身沒有正確配置,例如你從未設置過numberOfPages

順便說一句,在iOS 6中協調頁面控制與分頁滾動視圖的最簡單方法是使用UIPageViewController。

+0

是的,我認爲你是對的。手動設置不會更新pageControl值 – timpone 2013-03-03 18:29:37

相關問題