当前位置: 移动技术网 > IT编程>移动开发>Android > Android程序开发之UIScrollerView里有两个tableView

Android程序开发之UIScrollerView里有两个tableView

2019年07月24日  | 移动技术网IT编程  | 我要评论

武井もな,单挑高傲王子下,上海本地宝

一,效果图。

二,工程图。

 

三,代码。

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;
}

以上内容是小编给大家介绍的android程序开发之uiscrollerview里有两个tableview 的详细介绍,希望对大家有所帮助!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网