iOS:自定义UITableViewCell的实现需要调用super

标签 ios objective-c cocoa-touch uitableview

"* Assertion failure in -[PlayingCell layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2372/UIView.m:5776 2013-11-01 18:44:12.526 SnapTrack[216:c07] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. PlayingCell's implementation of -layoutSubviews needs to call super.'"

我正在尝试在 iOS6 模拟器中运行我的应用程序(我为 iOS7 设计的)。我的项目包含一个 TabBarController。在 tabbarcontroller 的第一个 View Controller 中,我有一个包含自定义 UITableViewCell 的 TableView 。他们加载没有问题。但是,当我切换到另一个选项卡时,我有另一个表格 View ,也有自定义单元格,我收到上面发布的错误。 viewControllers 的设置几乎相同(两者都有使用自动布局组织的 subview )。有没有人看到这个异常/知道如何解决它?

谢谢!

编辑:PlayingCell 的代码。

#import <UIKit/UIKit.h>

@interface PlayingCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *lblTrackNum;
@property (strong, nonatomic) IBOutlet UIImageView *albumArt;
@property (strong, nonatomic) IBOutlet UILabel *lblSongTitle;

@property (strong, nonatomic) IBOutlet UILabel *lblAlbumTitle;
@property (strong, nonatomic) IBOutlet UILabel *lblArtist;

@property (strong, nonatomic) IBOutlet UIImageView *imgPlay;
@property (strong,nonatomic) NSMutableDictionary *songInfo;

- (IBAction)downloadBtnPressed:(id)sender;

@end
#import "PlayingCell.h"

@implementation PlayingCell
@synthesize songInfo;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

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

    // Configure the view for the selected state
}

- (IBAction)downloadBtnPressed:(id)sender

{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[songInfo objectForKey:@"trackViewUrl"]]];
    NSLog(@"%@",[songInfo objectForKey:@"trackViewUrl"]);
}

-(void)layoutSubviews
{
    [super layoutSubviews];

}

最佳答案

按照错误说明进行操作。在您的自定义单元格类之一中,您似乎正在覆盖 layoutSubviews 方法。您必须在您的实现中调用 [super layoutSubviews]。这通常是第一行。

- (void)layoutSubviews {
    [super layoutSubviews];
    // the rest of your custom layout code
}

关于iOS:自定义UITableViewCell的实现需要调用super,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19736693/

相关文章:

ios - 在应用程序中实现绘图的最有效方法是什么?

ios - 模块 'Swift' : Permission denied 的导入文件

objective-c - cocoa NSTextField 行间距

iphone - 后台线程在 iPhone 3GS 上消耗 100% CPU 导致潜在的主线程

c - 递增 c 指针

ios - 搜索后自定义 UITableViewCell View 为空白

iphone - 如何计算 NSButton 的中心?

ios - UITableViewCell 子类不报告实际高度

ios - CSS Sprites 的 iPad/iPhone 问题,定位不正确

android - 照片或真人脸 如何使用 Android 相机检查