0
我正在繪製自定義表節標題視圖並在「tableView:viewForHeaderInSection:」方法中傳遞它。我得到一個崩潰,而表視圖嘗試繪製自己在屏幕上:在繪製自定義表格視圖節標題視圖時崩潰
有什麼能爲這種:-(原因
崩潰日誌說:
Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 10]'
*** Call stack at first throw:
0 CoreFoundation 0x3611a64f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x30638c5d objc_exception_throw + 24
2 CoreFoundation 0x3611a491 +[NSException raise:format:arguments:] + 68
3 CoreFoundation 0x3611a4cb +[NSException raise:format:] + 34
4 QuartzCore 0x30fd061d _ZL18CALayerSetPositionP7CALayerRKN2CA4Vec2IdEEb + 140
5 QuartzCore 0x30fd058b -[CALayer setPosition:] + 38
6 QuartzCore 0x30fd04d7 -[CALayer setFrame:] + 390
7 UIKit 0x32e1f455 -[UIView(Geometry) setFrame:] + 188
8 UIKit 0x32e200fb -[UILabel setFrame:] + 210
9 MyApp 0x003d4ed3 -[MyCustomView layoutSubviews] + 210
下面是代碼我的佈局子視圖:
- (void)layoutSubviews {
[super layoutSubviews];
CGFloat anEdgePadding = 28.0f;
CGFloat aTitleLabelWidth = [self.titleLabel.text sizeWithFont:[UIFont boldSystemFontOfSize:kFontSize16]].width;
CGFloat aSubTitleLabelWidth = [self.subTitleLabel.text sizeWithFont:[UIFont boldSystemFontOfSize:kFontSize10]].width;
self.titleLabel.frame = CGRectMake(myLeftRightMargin, -1, aTitleLabelWidth, self.bounds.size.height);
self.subTitleLabel.frame = CGRectMake(self.bounds.size.width - aSubTitleLabelWidth - anEdgePadding, 0, aSubTitleLabelWidth, self.bounds.size.height);
}
感謝, 阿比納夫
我將常量定義爲:#define myLeftRightMargin 8.0 – Abhinav