码迷,mamicode.com
首页 > 移动开发 > 详细

ios设置点击状态栏返回到顶部

时间:2015-05-30 23:50:42      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

在一个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设置点击状态栏返回到顶部

标签:

原文地址:http://www.cnblogs.com/qiulilin/p/4541223.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!