style sheet problem
I wrote code like:
+ (CGFloat)tableView:(UITableView*)tableView rowHeightForObject:(id)item {
CustomTTTableSubtitleItem* captionedItem = item;
CGFloat maxWidth = tableView.width - kHPadding*2;
CGSize titleSize = [captionedItem.title sizeWithFo开发者_如何学Gont:TTSTYLEVAR(myTitleFont) constrainedToSize:CGSizeMake(maxWidth, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap];
}
Got this exception:
2011-07-24 03:10:18.762 xinyou[15941:b303] -[TTDefaultStyleSheet myTitleFont]: unrecognized selector sent to instance 0x5b5e120 2011-07-24 03:10:18.765 xinyou[15941:b303] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TTDefaultStyleSheet myTitleFont]: unrecognized selector sent to instance 0x5b5e120' * Call stack at first throw: ( 0 CoreFoundation
0x0119a5a9 exceptionPreprocess + 185 1 libobjc.A.dylib 0x012ee313 objc_exception_throw + 44 2 CoreFoundation 0x0119c0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x0110b966 __forwarding + 966 4 CoreFoundation 0x0110b522 _CF_forwarding_prep_0 + 50 5 xinyou 0x000081f9 +[CustomTTTableSubtitleItemCell tableView:rowHeightForObject:] + 186 6 xinyou 0x000a6c92 -[TTTableViewVarHeightDelegate tableView:heightForRowAtIndexPath:] + 156 7 UIKit 0x0064a6d5 -[UISectionRowData
In this exception you can see [TTDefaultStyleSheet myTitleFont]: unrecognized selector sent to instance 0x5b5e120
but actually myTitleFont
defined in XYDefaultStyleSheet
and I've imported XYDefaultStyleSheet.h
in my class. XYDefaultStyleSheet.h
and XYDefaultStyleSheet.m
are like:
XYDefaultStyleSheet.h
#import "Three20/Three20.h"
@interface XYDefaultStyleSheet : TTDefaultStyleSheet
@property(nonatomic,readonly) UIColor* myHeadingColor;
@property(nonatomic,readonly) UIColor* mySubtextColor;
@property(nonatomic,readonly) UIColor* myTitleColor;
@property(nonatomic,readonly) UIFont* myTitleFont;
@property(nonatomic,readonly) UIFont* myHeadingFont;
@property(nonatomic,readonly) UIFont* mySubtextFont;
@end
XYDefaultStyleSheet.m
#import "XYDefaultStyleSheet.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation XYDefaultStyleSheet
///////////////////////////////////////////////////////////////////////////////////////////////////
// styles
///////////////////////////////////////////////////////////////////////////////////////////////////
// public colors
- (UIColor*)myTitleColor {
return [UIColor blackColor];
}
- (UIColor*)myHeadingColor {
return RGBCOLOR(80, 110, 140);
}
- (UIColor*)mySubtextColor {
return [UIColor grayColor];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// public fonts
- (UIFont*)myTitleFont {
return [UIFont boldSystemFontOfSize:16];
}
- (UIFont*)myHeadingFont {
return [UIFont boldSystemFontOfSize:13];
}
- (UIFont*)mySubtextFont {
return [UIFont systemFontOfSize:12];
}
@end
why always tell [TTDefaultStyleSheet myTitleFont]
... if the problem is really myTitleFont
, it should be [XYDefaultStyleSheet myTitleFont]
, why TTDefaultStyleSheet
?
got it! Init my style sheet in AppDelegate.
This is an answer to @Jason Zhao's answer about initialising within the AppDelegate
.
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[TTStyleSheet setGlobalStyleSheet:[[[CustomDefaultStyleSheet alloc]
init] autorelease]];
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
Original code is from here, which has a lot of useful information about using TTStyleSheet
's:
Three20 Stylesheets iPhone Tutorial
精彩评论