UITableView 代理方法大全

代理方法

//設置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    return 80;
}
//Section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 3;
}
//設置每個區(qū)有多少行共有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
//設置區(qū)域的名稱
- (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不實現(xiàn)滑動
    return YES;
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"手指撮動了");
    return UITableViewCellEditingStyleDelete;
//    //插入
//    return UITableViewCellEditingStyleInsert;
}
//設置CELL的樣式
       cell.selectionStyle = UITableViewCellSelectionStyleBlue;
        //灰色
       cell.selectionStyle = UITableViewCellSelectionStyleGray;
         //無顏色
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        //向右箭頭樣式
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        //向右箭頭button
         cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

TableView樣式

UITableViewStylePlain //矩形邊緣
UITableViewStyleGrouped //圓角邊緣

單元格樣式

UITableViewCellStyleDefault // img + title
UITableViewCellStyleSubtitle // img + title +subtitle
UITableViewCellStyleValue1, // img +title + subtitle(right)
UITableViewCellStyleValue2, // title + subtitle

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容