我的自定义单元未按我的期望加载。我已经改变了很长时间了,我知道我只是没有做我应该做的事情。

除了设计单元格之外,我没有做任何事情,在单元格原型上设置了约束,并为其分配了为其创建的自定义类,但我还没有改变。我认为这就是问题所在,因为我缺少自定义单元格类中的方法。

这是我的设计:

它是这样的:

我不知道发生了什么,但是我的图像没有显示,并且文本框忽略了约束。如果我在做些公然的事情,或者错过了什么,请填我吗?

编辑:我实际上有一个疯狂的长期错误。我是否应该重载某些内容以防止其自动布局?

2014-07-18 18:23:43.897 MeNext[4703:60b] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this:

(1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSLayoutConstraint:0x10933fab0 V:[UILabel:0x10933f900(90)]>",
    "<NSLayoutConstraint:0x1093411c0 V:|-(0)-[UILabel:0x10933f900]   (Names: '|':UITableViewCellContentView:0x10933f820 )>",
    "<NSLayoutConstraint:0x109341260 V:[UILabel:0x10933f900]-(0)-|   (Names: '|':UITableViewCellContentView:0x10933f820 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x10933a2f0 h=--& v=--& V:[UITableViewCellContentView:0x10933f820(91)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x10933fab0 V:[UILabel:0x10933f900(90)]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2014-07-18 18:23:43.900 MeNext[4703:60b] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSLayoutConstraint:0x109317d90 V:[UILabel:0x109317c50(90)]>",
    "<NSLayoutConstraint:0x10933c290 V:|-(0)-[UILabel:0x109317c50]   (Names: '|':UITableViewCellContentView:0x109332840 )>",
    "<NSLayoutConstraint:0x10933c330 V:[UILabel:0x109317c50]-(0)-|   (Names: '|':UITableViewCellContentView:0x109332840 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x1095685f0 h=--& v=--& V:[UITableViewCellContentView:0x109332840(91)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x109317d90 V:[UILabel:0x109317c50(90)]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2014-07-18 18:23:43.902 MeNext[4703:60b] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSLayoutConstraint:0x109320d30 V:[UILabel:0x109332d50(90)]>",
    "<NSLayoutConstraint:0x109337ad0 V:|-(0)-[UILabel:0x109332d50]   (Names: '|':UITableViewCellContentView:0x109332c90 )>",
    "<NSLayoutConstraint:0x109337b70 V:[UILabel:0x109332d50]-(0)-|   (Names: '|':UITableViewCellContentView:0x109332c90 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x109348490 h=--& v=--& V:[UITableViewCellContentView:0x109332c90(91)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x109320d30 V:[UILabel:0x109332d50(90)]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2014-07-18 18:23:43.904 MeNext[4703:60b] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSLayoutConstraint:0x109340530 V:[UIButton:0x109340340(17)]>",
    "<NSLayoutConstraint:0x109340c60 V:[UIButton:0x109340a20(17)]>",
    "<NSLayoutConstraint:0x109341120 V:|-(20)-[UIButton:0x109340340]   (Names: '|':UITableViewCellContentView:0x10933f820 )>",
    "<NSLayoutConstraint:0x109341350 V:[UIButton:0x109340a20]-(20)-|   (Names: '|':UITableViewCellContentView:0x10933f820 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x10933a2f0 h=--& v=--& V:[UITableViewCellContentView:0x10933f820(91)]>",
    "<NSLayoutConstraint:0x1093413a0 V:[UIButton:0x109340340]-(16)-[UIButton:0x109340a20]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x109340c60 V:[UIButton:0x109340a20(17)]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2014-07-18 18:23:43.905 MeNext[4703:60b] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSLayoutConstraint:0x10933b500 V:[UIButton:0x10933b310(17)]>",
    "<NSLayoutConstraint:0x10933bd30 V:[UIButton:0x10933baf0(17)]>",
    "<NSLayoutConstraint:0x10933c1f0 V:|-(20)-[UIButton:0x10933b310]   (Names: '|':UITableViewCellContentView:0x109332840 )>",
    "<NSLayoutConstraint:0x10933c420 V:[UIButton:0x10933baf0]-(20)-|   (Names: '|':UITableViewCellContentView:0x109332840 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x1095685f0 h=--& v=--& V:[UITableViewCellContentView:0x109332840(91)]>",
    "<NSLayoutConstraint:0x10933c470 V:[UIButton:0x10933b310]-(16)-[UIButton:0x10933baf0]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x10933bd30 V:[UIButton:0x10933baf0(17)]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2014-07-18 18:23:43.906 MeNext[4703:60b] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSLayoutConstraint:0x1093333d0 V:[UIButton:0x109333200(17)]>",
    "<NSLayoutConstraint:0x109336890 V:[UIButton:0x109336670(17)]>",
    "<NSLayoutConstraint:0x109337a30 V:|-(20)-[UIButton:0x109333200]   (Names: '|':UITableViewCellContentView:0x109332c90 )>",
    "<NSLayoutConstraint:0x109337c60 V:[UIButton:0x109336670]-(20)-|   (Names: '|':UITableViewCellContentView:0x109332c90 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x109348490 h=--& v=--& V:[UITableViewCellContentView:0x109332c90(91)]>",
    "<NSLayoutConstraint:0x109337d00 V:[UIButton:0x109333200]-(16)-[UIButton:0x109336670]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x109336890 V:[UIButton:0x109336670(17)]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

编辑2:这是我的CellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QueueCell" forIndexPath:indexPath];

    cell.textLabel.text = _tracks[indexPath.row][@"title"];
    if(_thumbnails.count == _tracks.count)
    {
        [cell.imageView sd_setImageWithURL:[NSURL URLWithString:_thumbnails[indexPath.row]]];
    }

    return cell;
}

最佳答案

我想如果要将ImageView放在所需的位置并使文本遵循约束,则需要对UITableViewCell进行子类化。创建类型为UITableViewCell的新类,将其连接到Storyboard中,然后使用
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QueueCell"];
这适用于Storyboard。

dequeueReusableCellWithIdentifier:@"" forIndexPath:indexPath

不适用于Storyboard。

然后,在您的单元格类中,连接IBOutlet ImageView,标签等。

关于ios - 自定义单元无法正确加载,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24834607/

10-11 19:48
查看更多