zoukankan      html  css  js  c++  java
  • 【代码笔记】iOS-UIScrollerView里有两个tableView

    一,效果图。

     

     

    二,工程图。

    三,代码。

    RootViewController.h

    复制代码
    #import <UIKit/UIKit.h>
    
    @interface RootViewController : UIViewController
    <UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource>
    {
        UIScrollView *_scrolView;
        UITableView *_tableView;
        UITableView *_tableView2;
        UITableViewCell *_cell;
    }
    
    @end
    复制代码

     

    RootViewConroller.m

    复制代码
    #import "RootViewController.h"
    
    @interface RootViewController ()
    
    @end
    
    @implementation RootViewController
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        
        [self initBackGroundView];
    }
    #pragma -mark -functions
    -(void)initBackGroundView
    {
        //tableView后的滚动条
        _scrolView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,19, 320, 460)];
        _scrolView.contentSize=CGSizeMake(320*2, 460);
        _scrolView.delegate=self;
        _scrolView.pagingEnabled=YES;
        _scrolView.showsVerticalScrollIndicator=NO;
        _scrolView.bounces=NO;
        [self.view addSubview:_scrolView];
        
        //tableView1
        _tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 19, 320, 460)];
        _tableView.tag=1;
        _tableView.delegate=self;
        _tableView.dataSource=self;
        _tableView.scrollEnabled=NO;
        [_scrolView addSubview:_tableView];
        
        //tableView2
        _tableView2=[[UITableView alloc]initWithFrame:CGRectMake(320, 19, 320, 460)];
        _tableView2.tag=2;
        _tableView2.delegate=self;
        _tableView2.dataSource=self;
        _tableView2.scrollEnabled=NO;
        [_scrolView addSubview:_tableView2];
        
    
    }
    #pragma -mark -UITableViewDelegate
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return 3;
    }
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return 125;
    }
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        _cell=[tableView dequeueReusableCellWithIdentifier:@"ID"];
        if (_cell==nil) {
            _cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ID"];
        }
        
        _cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
        if (tableView.tag==1){
         _cell.textLabel.text=@"1";
            
         }else if(tableView.tag==2){
             _cell.textLabel.text=@"2";
     
        }
        return _cell;
        
    }
    复制代码

     

     

     
     
  • 相关阅读:
    前端-浅谈Flex布局
    css-渐变简约的登录设计
    小程序-小程序后台原生图片识别
    小程序-云数据库实现好看的上传文件动态
    小程序-利用云开发操作云数据库实现点赞评论案例
    小程序-云存储实现对文件的上传下载
    小程序-浅谈云函数获取数据和云数据库api获取数据的区别
    小程序-简易加法教你如何使用云函数
    小程序-云数据库的add,get,remove,update
    小程序-你不得不知的Promise封装请求
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/5419950.html
Copyright © 2011-2022 走看看