升级到iOS8后,UITableView didSelectRowAtIndexPath无法正常工作

时间:2014-10-18 21:21:14

标签: ios objective-c iphone uitableview

我有一个iOS应用程序,其中包含几个UITableViews,所有这些都按预期工作 。我升级应用程序以处理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;
    }
}

3 个答案:

答案 0 :(得分:16)

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

在你的TableView中检查此默认设置, 如下图所示enter image description here

我有同样的问题,我在TableView&{39} NO Selection的{​​{1}}属性中提供了selection

如果您已完成相同操作,请在那里提供attribute inspector

希望这会对你有帮助!

答案 1 :(得分:2)

如果您选择了自动布局,cell.translatesAutoresizingMaskIntoConstraints=NO;将取消Xcode提供的自动布局。 另外,你能检查一下你所有的桌面视图吗?代表们完好无损?如果您的代理人没有设置,则点击表格视图单元格不会调用“已选择的行为”'方法

答案 2 :(得分:1)

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

相关问题