Remember the interview process last year, an interviewer asked me how to make a form. Because have not done before, at that time a bit of a confused force, today think up, and use TableView made a, hope not someone like me drop pit,
directly on the code :
////VIEWCONTROLLER.M//form-test////Created by ABC on 16/8/2.//copyright©2016 year Liuwenqiang. All rights reserved.//#import "ViewController.h"#defineWqwidth [UIScreen mainscreen].bounds.size.width#definewqheight [UIScreen mainscreen].bounds.size.height@interfaceViewcontroller () <UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>@property (strong,nonatomic) UITableView*TableView, @property (strong,nonatomic) Uiscrollview*ScrollView;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Self.view.backgroundColor=[Uicolor Graycolor]; Uiscrollview*scrollview =[[Uiscrollview alloc]init]; Scrollview.frame= CGRectMake (0, -, Wqwidth, wqheight); Scrollview.backgroundcolor=[Uicolor Graycolor]; Scrollview.contentsize= Cgsizemake (Wqwidth, wqheight+ -); ScrollView.Delegate=Self ; Self.scrollview=ScrollView; [Self.view Addsubview:scrollview]; for(intI=0; i<5; i++) {UITableView*tableview =[[UITableView alloc]init]; Tableview.frame= CGRectMake (i*wqwidth/5+0.5,0, (wqwidth-6*0.5)/5, Scrollview.contentSize.height); Tableview.backgroundcolor=[Uicolor Whitecolor]; TableView.Delegate=Self ; Tableview.datasource=Self ; Tableview.scrollenabled=NO; Tableview.tag=i; Self.tableview=TableView; Self.tableview.tableFooterView=[[UIView alloc]init]; [Self.scrollview Addsubview:tableview]; } }-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{return -;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{UITableViewCell*cell = [TableView dequeuereusablecellwithidentifier:@"Cell"]; if(!cell) {Cell= [[UITableViewCell alloc]initwithstyle:uitableviewcellstyledefault Reuseidentifier:@"Cell"]; Cell.textLabel.text= [NSString stringWithFormat:@"Line%ld",(Long) Indexpath.row]; Cell.textLabel.font= [Uifont systemfontofsize: -]; Cell.separatorinset= Uiedgeinsetsmake (0,- -,0,0); } returncell;}-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) section{if(Tableview.tag = =2|| Tableview.tag = =1) { return @"Books"; }Else{ returnNil; }}-(CGFloat) TableView: (UITableView *) TableView heightforheaderinsection: (nsinteger) section{if(Tableview.tag = =2|| Tableview.tag = =1) { returnwqheight/ -; }Else{ return 0; }}-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{returnwqheight/ -; }-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{[TableView Deselectrowatindexpath:indexpath Animated:yes]; NSLog (@"---------(%ld,%ld)",(Long) Tableview.tag, (Long) indexpath.row); }-(void) TableView: (UITableView *) TableView Willdisplaycell: (UITableViewCell *) cell Forrowatindexpath: (Nsindexpath *) indexpath{if([Cell Respondstoselector: @selector (setseparatorinset:)]) {[Cell Setseparatorinset:uiedgeinsetszero]; } if([Cell Respondstoselector: @selector (setlayoutmargins:)]) {[Cell Setlayoutmargins:uiedgeinsetszero]; } //According to the author's final meaning, add the following paragraph. if([Cell Respondstoselector: @selector (setpreservessuperviewlayoutmargins:)]) {[Cell Setpreservessuperviewlayo Utmargins:no]; }}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end
Because the table is generally the overall scrolling, it closed the tableview rolling, put TableView on the Uiscrollview, but feel this will affect the efficiency of operation, time to optimize it,
Do you have any good advice for me to say, thank you
IOS Authoring Table (data source control row, number of columns)