2009-11-23 82 views
1

我希望把我自己的自定義刪除了的UITableView細胞按鈕,當它進入編輯模式,類同的「+」,在同樣的位置插入添加按鈕,只是一個紅色的「X」 「+」按鈕是。我將如何做到這一點?UITableViewCell的自定義刪除按鈕

+0

有什麼不對的標準 「 - 」 按鈕? – gerry3 2009-11-23 01:58:37

+0

標準「 - 」按鈕位於左側,點擊的時候響起了刪除按鈕。我想在編輯模式下直接進入自定義刪除按鈕。我想在這裏的「+」按鈕,坐在右邊這個按鈕。 – 2009-11-23 02:31:52

回答

0

萬一別人曾經有這樣的疑問: 您必須設置editingAccessoryViewUITablViewCell到任何自定義UIView你希望它是。

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html

+13

該'editingAccessoryView'用於「編輯」模式,這是通過調用'setEditing啓用:對細胞或對錶animated'。這與滑動顯示刪除功能不同。如果你看看對的UITableViewCell的'willTransitionToState文檔:'方法,你會看到「刪除確認」是一個不同的模式,以「顯示編輯控件」。 – 2011-10-20 11:25:28

0

試試這個。

UIButton *btnDelete = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)]; 
[btnDelete setImage:[UIImage imageNamed:@"delet.png"] forState:UIControlStateNormal]; 
[btnDelete addTarget:self action:@selector(deleteButtonClicked:event:) forControlEvents:UIControlEventTouchUpInside]; 
cell.accessoryView = btnDelete; 
+0

不上tableViewCell右側accessoryView的?編輯控件位於左側。 – 2013-10-10 13:59:16

1

嘗試使用單元格willTransitionToState來實現它。

這樣在CustomTableCell.m:

- (void)willTransitionToState:(UITableViewCellStateMask)state{ 
    if (state == UITableViewCellStateShowingEditControlMask) { 
     customEditBtn = [[UIButton alloc] initWithFrame:CGRectMake(-32, 0, 42, self.contentView.height)]; 
     customEditBtn.adjustsImageWhenHighlighted = NO; 
     [customEditBtn setImage:_image forState:UIControlStateNormal]; 
     [self.contentView addSubview:customEditBtn]; 

    } 
} 

- (void)didTransitionToState:(UITableViewCellStateMask)state{ 
    [super didTransitionToState:state]; 
    if (state != UITableViewCellStateShowingEditControlMask) { 
     customEditBtn.alpha = 0; 
    } 
}