TableView のカスタム TableViewCell を作成しましたが、dealloc メソッド (カスタム セル クラス) があるとアプリがクラッシュします。テーブル セル クラスに使用される以下のコードを参照してください。
#import <UIKit/UIKit.h>
@interface CustomTableCell : UITableViewCell {
UILabel *nameLabel_;
UILabel *dateLabel_;
}
@property (nonatomic, retain) IBOutlet UILabel *nameLabel;
@property (nonatomic, retain) IBOutlet UILabel *dateLabel;
@end
#import "CustomTableCell.h"
@implementation CustomTableCell
@synthesize nameLabel = nameLabel_;
@synthesize dateLabel = dateLabel_;
- (void) dealloc {
[self.nameLabel release];
self.nameLabel = nil;
[self.dateLabel release];
self.dateLabel = nil;
[super dealloc];
}
@end
カスタム セル (cellForRowAtIndexPath) を作成するためのコード:
UITableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:@"DemoCell"];
if (Cell == nil){
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomTableCell" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[CustomTableCell class]])
{
Cell = (CustomTableCell *)currentObject;
break;
}
}
}
カスタム セルから dealloc メソッドを削除すると、すべて正常に動作します。そうしないと、例外が発生します(テーブルビューをスクロールすると):-[CALayer release]: 割り当て解除されたインスタンス 0x6fbc590 に送信されたメッセージ*
customTableViewCell に dealloc メソッドは必要ありませんか? この問題の解決策を見つけるのを手伝ってください。