iOS培訓教程——UITableView詳解

人這一路走來什麼纔是最富有的?回頭想想,風風火火的走了一圈,才發現原來擁有了知識、擁有技術的人才是最富有的,這些任誰也不能搶走它,只屬於你自己。現在還年輕的你一定不要迷失了方向,找準位置,走好接下來的每一步,那麼iOS培訓是不是你要走的路呢?

-、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多行顯示

163458730.jpg

//選中cell時的顏色

typedefenum{
UITableViewCellSelectionStyleNone,
UITableViewCellSelectionStyleBlue,
UITableViewCellSelectionStyleGray
}UITableViewCellSelectionStyle

做人也要像蠟燭一樣,在有限的一生中有一分熱發一分光,給人以光明,給人以溫暖。我是iOS培訓講師易慧雲,我爲“愛心”代言!只要你喜歡、有興趣,可以隨時關注我。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章