【发布时间】:2013-11-01 22:52:31
【问题描述】:
"* -[PlayingCell layoutSublayersOfLayer:] 中的断言失败, /SourceCache/UIKit_Sim/UIKit-2372/UIView.m:5776 2013-11-01 18:44:12.526 SnapTrack[216:c07] * 由于未捕获而终止应用程序 异常'NSInternalInconsistencyException',原因:'自动布局 执行 -layoutSubviews 后仍然需要。播放单元的 -layoutSubviews 的实现需要调用 super.'"
我正在尝试在 iOS6 模拟器中运行我的应用程序(我为 iOS7 设计的)。我的项目包含一个 TabBarController。在 tabbarcontroller 的第一个视图控制器中,我有一个包含自定义 UITableViewCell 的表视图。他们加载没有问题。但是,当我切换到另一个选项卡时,我有另一个表格视图,也有自定义单元格,我收到上面发布的错误。 viewController 的设置几乎相同(两者都有自动布局组织的子视图)。有没有人看到这个异常/知道如何解决它?
谢谢!
编辑: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];
}
【问题讨论】:
-
您确定在添加自定义表格单元格时拖动的是 UITableViewCell 而不是 UIView?
-
UIView 也可以添加到表格视图中。只有在启用自动布局时才会导致问题。
-
啊,我发现了错误。我使用 PlayingCell 作为基础结构(因为它有一个用于图像的 IBOutlet 而我懒得创建一个新的子类)作为表格视图标题的 nib 是很愚蠢的。无论如何,它似乎适用于 iOS 7,但使用 UITableViewCell 作为标题视图的自定义视图无论如何都不是一个好主意。我要关闭这个,其他人应该不会遇到这个问题!
标签: ios objective-c cocoa-touch uitableview