"* 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/