ios - 编辑 UITableViewCell 时将 UIActivityIndi​​cator 放在单元格中并禁用 UserInteraction

标签 ios objective-c iphone uitableview uiactivityindicatorview

当用户单击 UITableView 中的删除按钮时(编辑打开时),UIActivityIndi​​cator 会显示在 tableView 的中间,因为我想不出一种方法将它放在要删除的 Cell 的中间.这是我现在正在使用的代码:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {

        self.activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
        //cell.accessoryView = self.activityView;


        self.activityView.center = self.tableView.center;
        [self.tableView addSubview:self.activityView];

        [self.activityView startAnimating];
        .... rest of the code

所以 1)

第一个问题如何把indicatorView放在被删除的cell中间。

2) 发生这种情况时是否可以禁用删除按钮?我不希望用户大量单击按钮。

编辑1

我忘了提到我正在为电池 socket 使用自定义类。因此,在您要填充的普通 tableView 中,我使用此代码获取每个单元格

GamesInfoTableViewCell *cell1 = (GamesInfoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:otherSection];

最佳答案

试试这段代码。它会将 subview 添加到您要删除的单元格的中心。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {

        spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

        UITableViewCell * cell = [tableView cellForRowAtIndexPath: indexPath];
        // Setting Frame of Spinner..
        CGFloat x = (cell.frame.size.width-spinner.frame.size.width)/2;
        CGFloat y = (cell.frame.size.height-spinner.frame.size.height)/2;

        spinner.frame = CGRectMake(x, y, spinner.frame.size.width, spinner.frame.size.height);

        [cell addSubview: spinner];

        [spinner startAnimating];
        //Do YOUR WORK NOW
    }
}

快乐编码..:)

关于ios - 编辑 UITableViewCell 时将 UIActivityIndi​​cator 放在单元格中并禁用 UserInteraction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28828539/

相关文章:

ios - 在 iCloud 环境中检测应用程序 (IOS/OSX) 的首次运行

ios - 由于 MDFInternationalization 和 MaterialComponents 目录不存在,无法构建 ios

iphone - 如何在 objective-c 的表格 View 右侧添加加号按钮?

ios - 在 ios 的 uitableview 中自定义单元格编辑样式

iphone - 如何远程锁定iphone屏幕

ios - UIImagePickerController 不旋转和平移/缩放

ios - 无法将 UITextField 的内容从一个 Controller 传递到另一个 Controller

ios - 我们还应该支持 iOS 4 吗?

ios - 显示来自服务器的更新数据的 watch 套件

iOS : NSInputStream/NSOutputStream - CFNetwork SSLHandshake failed (-9806)