2010-10-25 138 views
4

我想在单元格中添加自定义的EditingAccessoryView,当用户刷卡代替删除按钮时,我想显示我的自定义视图。如何为UITableView添加自定义EditingAccessoryView?

+0

的显示您能够显示在指示灯按钮当按下红色删除按钮后,tableView处于编辑模式时显示单元格吗? – 2011-09-06 07:21:28

回答

-1

设计视图像波纹管例如

alt text

现在做的UIView IBOutlet中在.h文件中

IBOutlet UIView *accessoryView; 

连接会IBOutlet中您的设计视图。

现在.m文件组视图表格单元格的editingAccessoryView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
     cell.editingAccessoryView = accessoryView; 

     } 

} 


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

    return NO; 

} 
现在

当你刷卡您的自定义视图将代替删除按钮

+2

这似乎并没有在ios 6中工作。 – EightyEight 2013-06-28 21:42:34

+0

我现在也试图做到这一点,EightyEight,并找到这种解决方案 - 我推测会是正确的 - 在iOS 6(模拟器,在XCode 5测试版上)。 – Slowburner 2013-07-29 10:11:47

+1

这根本不起作用。首先,为“canEditRowAtIndexPath”返回NO将简单地阻止editAccessoryView显示出来。第二个问题是,您需要为每个新单元实例化一个新配件视图实例。最后......我不认为“dequeueReusableCellWithIdentifier”永远返回nil,这当然意味着editAccessoryView永远不会被分配。你真的测试过这个代码吗?我真的不这么认为。 – 2013-09-25 16:48:53

2

似乎没有这个功能。您只需使用下面的功能为删除确认按钮提供自定义文本。从厦门国际银行

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

谢谢。但我想添加两个按钮来代替一个删除按钮。不想更改该按钮的标题 – priyanka 2010-11-10 09:24:16

+0

这正是我试图弄清楚如何去做的。对不起,我不会赞成,因为它没有解决问题。但是,谢谢! – androidnotgenius 2014-02-03 15:55:13