【发布时间】:2011-09-03 20:56:16
【问题描述】:
对于带有自定义单元格的 UITableView,我有以下代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FolderCellViewController"];
if (cell == nil) {
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"FolderCellViewController" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
cell.editingAccessoryView=accessoryView; //accessoryView is a UIView within a UITableViewCell, and it is properly connected in IB
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
}
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return NO; //YES here makes a red delete button appear when I swipe
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
// [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
但是对于某些人来说,当我滑动时什么都没有发生。除了这个,我什么都没做——我还需要做什么才能让它工作吗?
编辑:显然我所做的只是为整个表格处于编辑模式时设置编辑样式,而不是在我在每个单独的单元格上滑动时设置编辑样式。所以我想要做的是,当我在每个单元格上滑动时,该单元格的自定义附件视图会出现。但我不知道该怎么做..
【问题讨论】:
标签: ios uitableview uikit