UITableView 常用方法總結

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{

   

    return 80;

}

//分區

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    // Return the number of sections.

    return 3;

}

//設置每個區有多少行共有多少行

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return 2;

}


//設置區域的名稱

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;

{

   return @"123";

}


//是否允許行移動

-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

{

    

    return YES;

}


//響應點擊事件

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath

{

    NSLog(@"響應單擊事件");

}


//小按鈕的響應事件

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath

{

    NSLog(@"accessoryButton的響應事件");  

    

}


//刪除按鈕的名字

-(NSString*)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return @"刪除";

}

//設置滑動,

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

    //ruturn NO不實現滑動

    return YES;

}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

    NSLog(@"手指撮動了");

    return UITableViewCellEditingStyleDelete;

//    //插入

//    return UITableViewCellEditingStyleInsert;

}

發佈了35 篇原創文章 · 獲贊 2 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章