Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 子类化uitableview单元格而不使用uitableviewcontroller_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 子类化uitableview单元格而不使用uitableviewcontroller

Ios 子类化uitableview单元格而不使用uitableviewcontroller,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正在尝试子类uitableviewcell 起初我使用uitableviewcontroller没有问题,一切正常 嗯。问题是我无法在uitableview的顶部插入静态视图。所以我 已开始使用uiview+uitableview。我将委托和数据源设置为uitable 但当我试图编译我的解决方案时,我得到了以下错误: 2015-03-04 15:00:53.087 News[7410:750801] *** Assertion failure in -[SubcategoryTableView

我正在尝试子类uitableviewcell

起初我使用uitableviewcontroller没有问题,一切正常

嗯。问题是我无法在uitableview的顶部插入静态视图。所以我

已开始使用uiview+uitableview。我将委托和数据源设置为uitable

但当我试图编译我的解决方案时,我得到了以下错误:

2015-03-04 15:00:53.087 News[7410:750801] *** Assertion failure in -[SubcategoryTableViewCell _setHostsLayoutEngine:], /SourceCache/UIKit/UIKit-3318.16.14/NSLayoutConstraint_UIKitAdditions.m:2760
2015-03-04 15:00:58.132 News[7410:750801] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Must translate autoresizing mask into constraints to have _setHostsLayoutEngine:YES.'
*** First throw call stack:
(0x182b59e48 0x19324c0e4 0x182b59d08 0x1839dd554 0x1873d6088 0x1873df4f0 0x1876f3c60 0x18771475c 0x1877eccc8 0x1877ecc68 0x1877ec984 0x1875c96f8 0x187832244 0x1877eccc8 0x1877ecc68 0x1877ec984 0x1875c96f8 0x1876f3c44 0x18771475c 0x1877eccc8 0x1877ec984 0x187714264 0x1877eccc8 0x1877ecc68 0x1877ec984 0x1877136ec 0x187446cac 0x1000292e8 0x187421854 0x1873e369c 0x1873e58f0 0x1873e582c 0x1873e5178 0x10003ad30 0x100344e30 0x100344df0 0x10034975c 0x182b116a0 0x182b0f748 0x182a3d1f4 0x18bbd35a4 0x18736e784 0x100029bf4 0x1938baa08)
libc++abi.dylib: terminating with uncaught exception of type NSException
关于代码的这一部分:

- (SubcategoryTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuseIdentifier = @"PlaceholderCell2";
    SubcategoryTableViewCell * sctvCell = [self.tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (sctvCell == nil) {
        sctvCell= [[SubcategoryTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]; 
    }
在故事板中,我将uitableviewcell设置为cell custome类。它是有效的

与uitableview控制器完美结合

这是我的类和子类代码:

嗯。问题是我无法在uitableview的顶部插入静态视图

有几种解决方法

  • 将静态视图放在
    窗口上(
    [self.tableView.window addSubview:staticView]
    )。在表视图控制器消失之前,您需要管理静态视图的删除

  • 具有具有静态视图的外部视图控制器。外部视图控制器在容器视图中具有表视图控制器



  • 回到您当前的问题。当您将表视图控制器替换为常规视图控制器时,是否重建了情节提要?简单地交换类型将导致错误。

    我曾经遇到过关于布局约束的类似问题。请修改UITableViewCell类构造函数,如下所示

        - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
        {
            self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
            if (self) {
                self.translatesAutoresizingMaskIntoConstraints = NO;
            // Your initializations here
        }
        return self;
        }
    

    这似乎是xCode 6的一个bug。有一个相关的讨论是的,我想是的。但这附近有工作吗!?在tableview单元格的nib文件中禁用自动布局可能是一个解决方案(?)im使用故事板作为解决方案。此外,uitableviewcell子类引用的是故事板中的同一单元格,没有任何额外的nib文件。感谢您的回复,是的,我已经完成了。甚至我在clean项目上也尝试过这样做,以查看结果,但仍然会得到相同的错误。有没有关于你的方法的示例?UITableViewController不是让这变得不可能吗?self是不可变的,如何分配self?