iOS培训教程——UITableView详解-创新互联

人这一路走来什么才是最富有的?回头想想,风风火火的走了一圈,才发现原来拥有了知识、拥有技术的人才是最富有的,这些任谁也不能抢走它,只属于你自己。现在还年轻的你一定不要迷失了方向,找准位置,走好接下来的每一步,那么iOS培训是不是你要走的路呢?

创新互联是一家以成都网站建设、网页设计、品牌设计、软件运维、成都网站推广、小程序App开发等移动开发为一体互联网公司。已累计为成都石凉亭等众行业中小客户提供优质的互联网建站和软件开发服务。

-、UITableView的建立

DataTable=[[UITableViewalloc]initWithFrame:CGRectMake(0,0,320,420)];
[DataTablesetDelegate:self];
[DataTablesetDataSource:self];
[self.viewaddSubview:DataTable];
[DataTablerelease];
二、UITableView各Method说
//Section总数
-(NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView{
returnTitleData;
}

//SectionTitles
//每个section显示的标题
-(NSString*)tableView:(UITableView*)tableViewtitleForHeaderInSection:(NSInteger)section{
return@"";
}

//指定有多少个分区(Section),默认为1
-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{
return4;
}

//指定每个分区中有多少行,默认为1
-(NSInteger)tableView:(UITableView*)tableViewnumberOfRowsInSection:(NSInteger)section{
}

//绘制Cell
-(UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath*)indexPath{
staticNSString*SimpleTableIdentifier=@"SimpleTableIdentifier";

UITableViewCell*cell=[tableViewdequeueReusableCellWithIdentifier:
SimpleTableIdentifier];

if(cell==nil){
cell=[[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier]autorelease];

}
cell.p_w_picpathView.p_w_picpath=p_w_picpath;//未选cell时的图片
cell.p_w_picpathView.highlightedImage=highlightImage;//选中cell后的图片
cell.text=//.....
returncell;
}

//行缩进
-(NSInteger)tableView:(UITableView*)tableViewindentationLevelForRowAtIndexPath:(NSIndexPath*)indexPath{
NSUIntegerrow=[indexPathrow];
returnrow;
}

//改变行的高度
-(CGFloat)tableView:(UITableView*)tableViewheightForRowAtIndexPath:(NSIndexPath*)indexPath{
return40;
}

//定位
[TopicsTablesetContentOffset:CGPointMake(0,promiseNum*44+Chapter*20)];

//返回当前所选cell
NSIndexPath*ip=[NSIndexPathindexPathForRow:rowinSection:section];
[TopicsTableselectRowAtIndexPath:ipanimated:YESscrollPosition:UITableViewScrollPositionNone];

[tableViewsetSeparatorStyle:UITableViewCellSelectionStyleNone];

//选中Cell响应事件
-(void)tableView:(UITableView*)tableViewdidSelectRowAtIndexPath:(NSIndexPath*)indexPath{

[tableViewdeselectRowAtIndexPath:indexPathanimated:YES];//选中后的反显颜色即刻消失
}

//判断选中的行(阻止选中第一行)
-(NSIndexPath*)tableView:(UITableView*)tableViewwillSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
NSUIntegerrow=[indexPathrow];
if(row==0)
returnnil;
returnindexPath;
}

//划动cell是否出现del按钮
-(BOOL)tableView:(UITableView*)tableViewcanEditRowAtIndexPath:(NSIndexPath*)indexPath{
}

//编辑状态
-(void)tableView:(UITableView*)tableViewcommitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath*)indexPath
{

[topicsTablesetContentSize:CGSizeMake(0,controller.promiseNum*44)];
//右侧添加一个索引表
-(NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView{
}

//返回Section标题内容
-(NSString*)tableView:(UITableView*)tableViewtitleForHeaderInSection:(NSInteger)section{
}

//cell右边按钮格式

typedefenum{
UITableViewCellAccessoryNone,//don'tshowanyaccessoryview
UITableViewCellAccessoryDisclosureIndicator,//regularchevron.doesn'ttrack
UITableViewCellAccessoryDetailDisclosureButton,//bluebuttonw/chevron.tracks
UITableViewCellAccessoryCheckmark//checkmark.doesn'ttrack
}UITableViewCellAccessoryType

//是否加换行线

typedefenum{
UITableViewCellSeparatorStyleNone,
UITableViewCellSeparatorStyleSingleLine
}UITableViewCellSeparatorStyle

//改变换行线颜色lyttzx.com

leView.separatorColor=[UIColorblueColor];

//自定义划动时del按钮内容
-(NSString*)tableView:(UITableView*)tableView
titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexPath

//跳到指的roworsection
[tableViewscrollToRowAtIndexPath:[NSIndexPathindexPathForRow:0inSection:0]atScrollPosition:UITableViewScrollPositionBottomanimated:NO];

三、在UITableViewCell上建立UILable多行显示

iOS培训教程——UITableView详解

//选中cell时的颜色

typedefenum{
UITableViewCellSelectionStyleNone,
UITableViewCellSelectionStyleBlue,
UITableViewCellSelectionStyleGray
}UITableViewCellSelectionStyle

做人也要像蜡烛一样,在有限的一生中有一分热发一分光,给人以光明,给人以温暖。我是iOS培训讲师易慧云,我为“爱心”代言!只要你喜欢、有兴趣,可以随时关注我。

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文标题:iOS培训教程——UITableView详解-创新互联
标题链接:http://pwwzsj.com/article/eeohc.html