【问题标题】:UITableView didSelectRowAtIndexPath not working after upgrade to iOS8升级到 iOS8 后 UITableView didSelectRowAtIndexPath 不起作用
【发布时间】:2014-10-18 21:21:14
【问题描述】:

我有一个 iOS 应用程序,其中包含多个 UITableView,所有这些都按预期工作 .我升级应用程序以处理 iOS8

从那时起,我在将自定义单元格加载到表格视图中时遇到了问题,他的笔尖在 ib 中的框选中了“使用自动布局”。然后我在我的自定义单元格上取消选中所有这些,从那时起,我所有 UITableViews 的单元格不仅不调用 didSelectRowAtIndex 路径方法,而且在触摸时也不会突出显示。

我已通过添加检查所有单元格是否处于活动状态

if(cell.userInteractionEnabled){NSLog(@"is enabled");}else{NSLog(@"is not enabled");}

所有加载的单元格都将“启用”写入日志

我正在通过故事板中的 ib 设置委托和数据源,在我更改“使用自动布局”并升级以在 iOS 8 上运行之前,所有这些都正常工作。

我错过了什么?

这是我创建单元格的代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"TableCellWithNumberCellIdentifier";
    if( events.count>indexPath.row &&[[[events objectAtIndex:indexPath.row] objectForKey:@"tag"] integerValue] == -1)
    {
        EventsMonthSeparator *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil)
        {
            cell.translatesAutoresizingMaskIntoConstraints=NO;
            cell = (EventsMonthSeparator *)[EventsMonthSeparator cellFromNibNamed:@"EventsMonthSeparator"];
            cell.date.text=[[events objectAtIndex:indexPath.row] objectForKey:@"date"];
            [Functions setFontFamily:@"Neutra Display" forView:cell andSubView:YES];
            if(cell.userInteractionEnabled){NSLog(@"is enabled");}else{NSLog(@"is not enabled");}
        }
        return cell;
    }else
    {
        eventsRow *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil)
        {
            cell.translatesAutoresizingMaskIntoConstraints=NO;
            cell = (eventsRow *)[eventsRow cellFromNibNamed:@"eventsRow"];
            cell.description.text=[[events objectAtIndex:indexPath.row] objectForKey:@"name"];
            cell.timedate.text=[[events objectAtIndex:indexPath.row]objectForKey:@"date"];
            cell.image.image=[UIImage imageNamed:@"tiledrinks"];
            cell.status.text=[Functions statusForIndex:[[[events objectAtIndex:indexPath.row] objectForKey:@"booked"] intValue]];
            [Functions setFontFamily:@"Neutra Display" forView:cell andSubView:YES];
            cell.tag=1;
            [cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
            if(cell.userInteractionEnabled){NSLog(@"is enabled");}else{NSLog(@"is not enabled");}
        }
        return cell;
    }
}

【问题讨论】:

  • 您在打开自动布局的情况下将自定义单元格加载到表格视图中时遇到了什么问题?最好解决这个问题,并继续使用 apt 布局。
  • 开机后完美运行

标签: ios objective-c iphone uitableview


【解决方案1】:

请同时检查您的自定义单元格的xib 中的Auto-Layout 是否为OFF(未选择的tickMark)。

并在您的TableView 中检查此默认设置, 如下图所附

我曾经遇到过同样的问题,我在 TableView 的attribute inspectorselection 属性中给出了NO Selection

如果你也做了同样的事情,那就给Single selection

希望对你有帮助!

【讨论】:

  • 嘿,你拯救了我的一天......如果“选择 = 无选择”,它不会调用 didSelectRowAtIndexPath 委托。
【解决方案2】:

如果您选择了自动布局,cell.translatesAutoresizingMaskIntoConstraints=NO; 将否定 Xcode 提供的自动布局。 另外,你能检查一下你所有的 tableViews 的代表是否完好无损吗?如果您的委托未设置,则点击表格视图单元格将不会调用“didSelectRow”方法。

【讨论】:

  • 代理和数据源在 ib.xml 中设置。方法 cellForRowAtIdexPath、willDisplayCell forRowAtIndexPath 和 heightForRowAtIndexPath 都正常工作
  • 只是为了检查:尝试将 NSLog("Hello") 放入您的 didSelectRow 方法并注释掉其他所有内容。
  • 仅供参考,您已将这一行:cell.translatesAutoresizingMaskIntoConstraints=NO; 放在重新分配单元格 (cell = ...) 之前,因此它不会产生任何影响。试着把它移低。
【解决方案3】:

您可以在TableView中选择“编辑期间单选”, 例如:

【讨论】:

    猜你喜欢
    • 2019-04-09
    • 1970-01-01
    • 2015-12-08
    • 2017-07-06
    • 2017-06-30
    • 1970-01-01
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多