ios設定點擊狀態列返回到頂部

來源:互聯網
上載者:User

標籤:

在一個scrollview中橫向有多個tableview,點擊狀態列,tableview要返回到頂部
要將所有scrollview 以及tableview 的scrollToTop設定為NO。顯示的tableview的scrollToTop設定為TRUE。

@property(nonatomic,strong) NSMutableArray *tdoclist;

//設定一個數組,儲存tableview

self.tdoclist=[NSMutableArray arrayWithCapacity:10];
for (int i=0; i<[self.category count]+1; i++) {
[[[CommenData alloc]init] setCategoryIndex:[self getCategoryIndex:i]];
if (i==0) {
self.doctable=[self.storyboard instantiateViewControllerWithIdentifier:@"docview"];
self.doctable.view.frame=CGRectMake(r.size.width*i, 0.0, r.size.width, r.size.height-40);
[self addChildViewController:self.doctable];
self.doctable.tableView.scrollsToTop=YES;
[self.tdoclist addObject:self.doctable];
[self.tableScroll addSubview:self.doctable.view];
}else{
self.tdoctable=[self.storyboard instantiateViewControllerWithIdentifier:@"tdocview"];
self.tdoctable.view.frame=CGRectMake(r.size.width*i, 0.0, r.size.width, r.size.height-40);
[self addChildViewController:self.tdoctable];
self.tdoctable.tableView.scrollsToTop=NO;
[self.tdoclist addObject:self.tdoctable];
[self.tableScroll addSubview:self.tdoctable.view];
}
}

 

//左右滑動頁面切換tableview時切換 tableview的scrollToTop屬性

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    //載入之後的一頁
    if (scrollView==self.tableScroll) {
                CGFloat pageWidth=scrollView.frame.size.width;
        int page=floor((scrollView.contentOffset.x-pageWidth/2)/pageWidth)+1;
        if (page!=indexPage) {
            //可以繼續滾動
            if (indexPage<[self.category count]+1) {
                indexPage=page;
                [self.scrollnavi setSelectedIndex:indexPage];
                for (int i=0; i<self.tdoclist.count; i++) {
                    TDocTableViewController *tdocs = self.tdoclist[i] ;
                    if (i==indexPage) {
                        tdocs.tableView.scrollsToTop=YES;
                    }else{
                        tdocs.tableView.scrollsToTop=NO;
                    }
                }
                //若直接用self.tdoc 只會重新整理最後一個頁面
                 TDocTableViewController *tdoc = self.tdoclist[indexPage] ;
                [tdoc refreshData];
                
            }
            
        }

    }

}

ios設定點擊狀態列返回到頂部

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.