3

カスタムTableViewCellを持つtableViewがあります。これをレイアウトするために .xib ファイルを使用していません。問題は、テーブルが読み込まれるはずのときに、次のエラーが表示されるTerminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage nsli_superitem]: unrecognized selector sent to instance 0x91899b0'ことです。ここで何が間違っているのかわかりません。セルの .m ファイルは次のとおりです。

#import "TCMExhibitListCell.h"

@implementation TCMExhibitListCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
    [self setListImage:[[UIImage alloc] init]];
    [self setTitleLabel:[[UILabel alloc] init]];


    NSDictionary *names = @{@"listImage" : [self listImage]};

    NSString *fmt = @"H:|-0-[listImage]";

    NSArray *imgH = [NSLayoutConstraint constraintsWithVisualFormat:fmt
                                                            options:0
                                                            metrics:nil
                                                              views:names];
    [[self contentView] addConstraints:imgH];
}
return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}

@end

テーブルビューコントローラーでセルが読み込まれる場所は次のとおりです

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TCMExhibitListCell *c = [tableView dequeueReusableCellWithIdentifier:@"TCMExhibitListCell"];

if (!c) {
    c = [[TCMExhibitListCell alloc] initWithStyle:UITableViewCellStyleDefault
                               reuseIdentifier:@"TCMExhibitListCell"];
}

TCMExhibitRemote *e = [[self exhibits] objectAtIndex:[indexPath row]];

NSString *imageFile = [NSString stringWithFormat:@"%@/%@.jpg",[[TCMExhibitFeedStore sharedStore] imagePathByType:@"listImage"],[e image]];

[c setListImage:[UIImage imageNamed:imageFile]];

return c;
}
4

3 に答える 3

20

少しグーグルnsli_superitemすると、自動レイアウトに関連付けられていることがわかります。どちらがあなたを に向け、どれ[[self contentView] addConstraints:imgH];があなたを に向けNSString *fmt = @"H:|-0-[listImage]";、そして に向け[self setListImage:[[UIImage alloc] init]];ます。

つまり、画像は UI アイテムではないため、画像に基づいてレイアウトを設定することはできません。

おそらく、どこかで画像ビュービューに基づいてレイアウトを行う必要があります...

于 2013-07-10T13:51:11.600 に答える
1

私の問題は、UIViewControllerVisual Format Language を使用して制約で a を使用しようとしていたことでした。UIViewController を使用するように制約を変更するとview、クラッシュが修正されました。

containerView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[playerVC]-0-|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["playerVC" : playerVC.view])) // note playerVC.view here, not playerVC
于 2016-06-21T18:01:18.950 に答える
0

これを設定するのを忘れていると思います。

self.listImage.translatesAutoresizingMaskIntoConstraints = NO;
于 2015-01-09T10:26:53.273 に答える