簡體   English   中英

輕按tableview單元格內的按鈕時,觸發UITableViewCellEditingStyleDelete

[英]Trigger UITableViewCellEditingStyleDelete when button inside tableview cell is tapped

在此處輸入圖片說明

這是我的單元格,當我點擊單元格左側的圖標時,它會觸發,就像用戶滑動該單元格一樣。

我有UITableViewCell的子類,也連接了icon(button)。 看起來像這樣

- (IBAction)didPressMinusButton:(id)sender {

    [self setEditing:YES animated:YES];

}

在我的tableView中我也有這個

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    //my code for deletion here
}

當用戶點擊我的單元格左側的圖標時,我想實現顯示刪除或刪除的功能。 基本上就像滑動,但在這種情況下,我只是通過點擊觸發它。

您的意思是,當用戶點擊左側的減號圖標時,刪除功能應該起作用而不是滑動。

如果是,則只需刪除此代碼或為此添加注釋

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    //my code for deletion here
} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM