首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可可触觉- UITableView setEditing不会显示特定的细胞

可可触觉- UITableView setEditing不会显示特定的细胞
EN

Stack Overflow用户
提问于 2012-01-30 01:20:50
回答 1查看 2.7K关注 0票数 0

我已经为这个问题挣扎了2个小时了,我无法让它开始工作。

我有一个视图控制器,上面有一个表视图,上面有一个项目列表。当用户触摸导航栏中的编辑按钮时,表视图应该进入“编辑模式”,在条目列表下,应该出现一个新单元格,只有在处于“编辑模式”时才能看到。

因此,在我的-tableView:cellForRowAtIndexPath:方法中,我检查if (tableView.isEditing)来设置单元格。我尝试过重写-setEditing:animated:并执行[tableView reloadData]调用,但我就是无法让它正常工作。

这就是我的-setEditing:animated:的样子:

代码语言:javascript
复制
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [self.groupDetailsTableView setEditing:editing animated:animated];
}

我的-tableView:cellForRowAtIndexPath:

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    NSUInteger row = [indexPath row];


    if (tableView.isEditing) {

            // Other tableview code has been omitted

            UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                                           reuseIdentifier:nil];

            // Set the background view of the cell to be transparent        
            UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
            backView.backgroundColor = [UIColor clearColor];
            cell.backgroundView = backView;

            UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
            [deleteButton setFrame:[cell.contentView frame]];
            [deleteButton setFrame:CGRectMake(0, 0, cell.bounds.size.width-20, 44)];
            [deleteButton setBackgroundImage:[UIImage imageNamed:@"redbutton.png"] forState:UIControlStateNormal];
            [deleteButton setTitle:@"Delete Group" forState:UIControlStateNormal];
            [deleteButton.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
            [deleteButton.titleLabel setShadowColor:[UIColor lightGrayColor]];
            [deleteButton.titleLabel setShadowOffset:CGSizeMake(0, -1)];
            [deleteButton addTarget:self action:@selector(deleteGroup) forControlEvents:UIControlEventTouchUpInside];

            [cell.contentView addSubview:deleteButton];

            return cell;

        }
}

当用户触摸编辑按钮时,我从一个方法调用[self setEditing:YES animated:YES];。我也试过打电话给[super setEditing:YES animated:YES];[self.groupDetailsTableView setEditing:YES animated:YES];

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-30 01:34:57

http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/ManageInsertDeleteRow/ManageInsertDeleteRow.html#//apple_ref/doc/uid/TP40007451-CH10-SW19我自己找到了答案

显然,-tableView:cellForRowAtIndexPath:在调用-setEditing:animated:时不会自动调用

因此,为了让一个新的单元格“出现”,我在调用setEditing之后将alpha设置为0.0,然后设置为1.0 .

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9058388

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档