我有一個UITableView包含每個UITableviewCell的2個按鈕。 如何在UITableview處於編輯模式時隱藏按鈕? 感謝iOs - 進入編輯模式時隱藏按鈕
3
A
回答
2
我建議你到子類的UITableViewCell並添加按鈕爲屬性,那麼他們hidden
屬性設置爲YES:
@interface CustomCell: UITableViewCell
{
UIButton *btn1;
UIButton *btn2;
}
@property (nonatomic, readonly) UIButon *btn1;
@property (nonatomic, readonly) UIButon *btn2;
- (void)showButtons;
- (void)hideButtons;
@end
@implementation CustomCell
@synthesize btn1, btn2;
- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSStrig *)reuseId
{
if ((self = [super initWithStyle:style reuseidentifier:reuseId]))
{
btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// etc. etc.
}
return self;
}
- (void) hideButtons
{
self.btn1.hidden = YES;
self.btn2.hidden = YES;
}
- (void) showButtons
{
self.btn1.hidden = NO;
self.btn2.hidden = NO;
}
@end
而在你的UITableViewDelegate:
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
[(CustomCell *)[tableView cellForRowAtIndexPath:indexPath] hideButtons];
}
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
[(CustomCell *)[tableView cellForRowAtIndexPath:indexPath] showButtons];
}
希望它能幫助。
2
只是想用一個更簡單的解決方案來更新這個線程。爲了隱藏的UITableViewCell
自定義子類特定的元素,只需覆蓋一個方法UITableViewCell
(斯威夫特實現):
override func setEditing(editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
// Customize the cell's elements for both edit & non-edit mode
self.button1.hidden = editing
self.button2.hidden = editing
}
這將自動爲每個單元調用父UITableView
的-setEditing:animated:
方法之後調用。
相關問題
- 1. 如何在UITableViewCell中編輯模式時隱藏按鈕
- 2. 啓用編輯模式時如何隱藏自定義按鈕?
- 3. 空時隱藏編輯按鈕
- 4. 按下時隱藏iOS按鈕
- 5. JTable - 按Tab鍵進入編輯模式
- 6. 編輯模式按鈕
- 7. 如何在UITableViewCell進入/退出編輯模式時隱藏/顯示控件?
- 8. iOS倒計時顯示隱藏按鈕
- 9. 如何通過代碼隱藏爲gridview編輯編輯按鈕?
- 10. Magento刪除(顯示/隱藏編輯器)按鈕管理模塊
- 11. 導航控制器上的編輯按鈕不會進入編輯模式
- 12. 進入UIImagePickerController編輯模式
- 13. 同時進入編輯模式的UITableViewCell
- 14. 設置爲隱藏後隱藏的按鈕不隱藏 - IOS
- 15. Dynamics AX 2012:在AxGridView編輯模式下,如何隱藏保存按鈕
- 16. 以編程方式隱藏和取消隱藏按鈕
- 17. 按下按鈕時啓用tableView的編輯模式
- 18. 添加左按鈕時隱藏返回按鈕ios
- 19. 隱藏輸入按鈕
- 20. iOS編輯按鈕執行
- 21. 暫時隱藏UINavigationBar按鈕
- 22. 隱藏按鈕
- 23. 隱藏按鈕
- 24. 編輯內容時隱藏鍵盤UIWebView
- 25. 隱藏標籤和顯示按鈕ios
- 26. Xamarin IOS隱藏欄後退按鈕
- 27. 如何在未處於編輯模式時隱藏插入符號?
- 28. GridView - 使用代碼隱藏複選框(按鈕單擊)將多行輸入編輯模式
- 29. Odoo如何隱藏基於用戶組的編輯按鈕?
- 30. 在選定的UITABLEVIEW單元上隱藏/禁用編輯按鈕?
感謝@ H2CO3,它適用於我更新單個單元格時,但是當您想要在所有單元格處於編輯模式時應用此方法嗎? (意思是當所有行上出現「減號」按鈕時)? – Stan92
我發現這隱藏按鈕: - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath :(NSIndexPath *)indexPath {(CustomCell *) [tableView cellForRowAtIndexPath:indexPath] hideButtons]; return UITableViewCellEditingStyleDelete; } 但是,當我離開編輯模式時,不知道將它們顯示出來。 – Stan92
無論如何,當您更新單元格時不會調用此方法。它在其他委託方法中被調用。 – 2012-01-21 21:23:49