2011-07-22 3 views
1

TTTableMessageItemCellをサブクラス化すると、EXC_BAD_ACCESSランタイムエラーが発生します。 Anythign間違っている?サブクラス化TTTableMessageItemCell、何か間違っていますか?

CustomTTTableSubtitleItemCell.h

#import "Three20/Three20.h" 
@interface CustomTTTableSubtitleItemCell : TTTableMessageItemCell { 
    TTButton *_rightButton; 
} 

@end 

CustomTTTableSubtitleItemCell.m

#import "CustomTTTableSubtitleItemCell.h" 
#import "CustomTTTableSubtitleItem.h" 
#import "XYDefaultStyleSheet.h" 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
/////////////////////////////////////////////////////////////////////////////////////////////////// 

static CGFloat kHPadding = 10; 
static CGFloat kVPadding = 15; 


@interface ButtonStyleSheet : TTDefaultStyleSheet 
@end 

@implementation ButtonStyleSheet 

- (TTStyle*)blueToolbarButton:(UIControlState)state { 
    TTShape* shape = [TTRoundedRectangleShape shapeWithRadius:4.5]; 
    UIColor* tintColor = RGBCOLOR(30, 110, 255); 
    return [TTSTYLESHEET toolbarButtonForState:state shape:shape tintColor:tintColor font:nil]; 
} 

@end 


@implementation CustomTTTableSubtitleItemCell 


+ (CGFloat)tableView:(UITableView*)tableView rowHeightForItem:(id)item { 
    CustomTTTableSubtitleItem* captionedItem = item; 

    CGFloat maxWidth = tableView.width - kHPadding*2; 

    CGSize titleSize = [captionedItem.title sizeWithFont:TTSTYLEVAR(myTitleFont) 
            constrainedToSize:CGSizeMake(maxWidth, CGFLOAT_MAX) 
             lineBreakMode:UILineBreakModeWordWrap]; 

    CGSize textSize = [captionedItem.text sizeWithFont:TTSTYLEVAR(myHeadingFont) 
            constrainedToSize:CGSizeMake(maxWidth, CGFLOAT_MAX) 
             lineBreakMode:UILineBreakModeWordWrap]; 
    CGSize subtextSize = [captionedItem.caption sizeWithFont:TTSTYLEVAR(mySubtextFont) 
              constrainedToSize:CGSizeMake(maxWidth, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap]; 

    return kVPadding*2 + titleSize.height + textSize.height + subtextSize.height + kVPadding; 
} 




- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)identifier { 
    if (self = [super initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:identifier]) { 
     _item = nil; 
     [TTStyleSheet setGlobalStyleSheet:[[[ButtonStyleSheet alloc] init] autorelease]]; 


    } 
    return self; 
} 


- (void)layoutSubviews { 
    [super layoutSubviews]; 

    [self.detailTextLabel sizeToFit]; 
    self.detailTextLabel.top = kVPadding; 

    self.textLabel.height = self.detailTextLabel.height; 

    //_rightButton.frame = CGRectMake(20, self.detailTextLabel.bottom + kVPadding, kImageWidth, kImageHeight); 

     //_rightButton.alpha = !self.showingDeleteConfirmation; 
     [_rightButton sizeToFit]; 
     _rightButton.left = self.contentView.width - (_timestampLabel.width + kHPadding); 
     _rightButton.top = self.height/2; 



} 

- (id)object { 
    return _item; 
} 

- (void)setObject:(id)object { 
    if (_item != object) { 
     [super setObject:object]; 

     CustomTTTableSubtitleItem* item = object; 


     //self.textLabel.textColor = TTSTYLEVAR(myHeadingColor); 
//  self.textLabel.font = TTSTYLEVAR(myHeadingFont); 
//  self.textLabel.textAlignment = UITextAlignmentRight; 
//  self.textLabel.contentMode = UIViewContentModeCenter; 
//  self.textLabel.lineBreakMode = UILineBreakModeWordWrap; 
//  self.textLabel.numberOfLines = 0; 
//  
//  self.detailTextLabel.textColor = TTSTYLEVAR(mySubtextColor); 
//  self.detailTextLabel.font = TTSTYLEVAR(mySubtextFont); 
//  self.detailTextLabel.textAlignment = UITextAlignmentLeft; 
//  self.detailTextLabel.contentMode = UIViewContentModeTop; 
//  self.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap; 


     _rightButton = [TTButton 
         buttonWithStyle:@"blueToolbarButton:" title:item.rightButtonTitle]; 




    } 
} 

- (void)dealloc { 
    TT_RELEASE_SAFELY(_rightButton); 
    [super dealloc]; 
} 

@end 

答えて

0

あなたはあなたのdealloc機能でそれを解放している間、自動解放を使用してTTButtonを作成しています。リリースプールとdeallocの両方が_rightButton TTButtonを解放しようとしています。あなたのヘッダファイル内

、追加してみてください。そして、

@property (nonatomic, readonly, retain) TTButton*  rightButton; 

そして、あなたのソースファイルで彼のget関数を使用してTTButtonを作成する:

/////////////////////////////////////////////////////////////////////////////////////////////////// 
- (TTButton*)rightButton { 
if (!_rightButton) { 
    _rightButton = [[TTButton 
        buttonWithStyle:@"blueToolbarButton:" title:item.rightButtonTitle] retain]; 

    [self.contentView addSubview:rightButton]; 
    } 
return rightButton; 
} 

rightButtonを使用する場合は、自己を使用してください.rightButtonではなく、layout関数内でのように.rightButtonではなく、作成するためにオブジェクト化する必要があるためです。

self.rightButton.frame = CGRectMake(20, self.detailTextLabel.bottom + kVPadding, kImageWidth, kImageHeight); 

私はThree20UI/TTTableMessageItemCell.h &ソースファイルを開くと、要素の一つの行動をコピーしようと示唆しています。それが私のしたことです。