武井もな,单挑高傲王子下,上海本地宝
一,效果图。
二,工程图。
三,代码。
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 的详细介绍,希望对大家有所帮助!
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android apk 项目一键打包并上传到蒲公英的实现方法
Android 自定义LineLayout实现满屏任意拖动功能的示例代码
android 限制某个操作每天只能操作指定的次数(示例代码详解)
Android 集成 google 登录并获取性别等隐私信息的实现代码
网友评论