2013-11-01 29 views
1

*在斷言失敗 - [PlayingCell layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2372/UIView.m:5776 2013年11月1日 18 :44:12.526 SnapTrack [216:C07 *終止應用程序由於未捕獲的異常 'NSInternalInconsistencyException',理由是: '自動佈局 執行-layoutSubviews後仍然需要PlayingCell的 實施-layoutSubviews的需要調用超。'」的iOS:實現自定義的UITableViewCell中需要調用超

我正在嘗試在iOS6模擬器中運行我的應用程序(我爲iOS7設計)。我的項目包含一個TabBarController。在tabbarcontroller的第一個視圖控制器中,我有一個包含自定義UITableViewCell的表視圖。它們加載沒有問題。但是,當我切換到另一個選項卡,我有另一個表視圖,也與自定義單元格,我得到上面發佈的錯誤。 viewControllers幾乎完全相同(都有自動佈局組織子視圖)。有沒有人看到這個例外/知道如何解決它?

謝謝!

編輯:代碼爲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]; 

} 
+0

你確定當你添加自定義表格單元時,你拖動了一個UITableViewCell而不是UIView? – hasan83

+0

UIView也可以添加到表視圖。它只是在啓用自動佈局時造成問題。 – hasan83

+0

啊我發現了錯誤。這是愚蠢的我使用的PlayCell作爲基礎結構(因爲它有一個圖像的IBOutlet,我懶得創建一個新的子類)的表視圖標題的筆尖。無論如何,它似乎適用於iOS 7,但使用UITableViewCell作爲標題視圖的自定義視圖並不是一個好主意。我要關閉這個,沒有人會遇到這個問題! – JoshDG

回答

1

做什麼錯誤狀態。在您的自定義單元類之一中,您似乎覆蓋了layoutSubviews方法。您的實施必須致電[super layoutSubviews]。這通常是第一行。

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

我添加了我的自定義單元的代碼。我添加了該代碼,但仍然出現錯誤。 – JoshDG

相關問題