【发布时间】:2011-11-25 13:49:13
【问题描述】:
我有一些我在以前的项目中使用过的代码,它运行良好。现在,我使用该旧代码作为解决当前项目中相同问题的指南。问题:现在可以正常工作的相同方法使我的应用程序崩溃。也许你们中的一个看到我在这里做错了什么?
在我当前的项目中,我有一个自定义的 tableviewcell,其中包含一个名为“VerlaufView”的自定义 UIView。我在 Interface Builder 中连接了所有东西,并检查了它是否正常工作。所以这是我的自定义 UIView:
接口定义:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface VerlaufView : UIView {
CALayer* mainLayer;
}
@property (strong,nonatomic) CALayer* mainLayer;
-(void) initialisieren;
@end
这就是实现。请注意,实现包含内部类“VerlaufDelegate”,这将是处理 calayer 上的绘图的委托。
#import "VerlaufView.h"
static bool debug = YES;
#pragma mark VerlaufDelegate
@interface VerlaufDelegate : NSObject {
UIView* layersParent;
}
@property (nonatomic,strong) UIView* layersParent;
-(id)initWithView:(UIView*)view;
@end
@implementation VerlaufDelegate
@synthesize layersParent;
-(id)initWithView:(UIView*)view {
if( debug ) NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
self = [super init];
if( self )
self.layersParent = view;
if( debug ) NSLog(@">>> Leaving %s <<<", __PRETTY_FUNCTION__);
return self;
}
- (void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx {
if( debug ) NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
if( debug ) NSLog(@">>> Leaving %s <<<", __PRETTY_FUNCTION__);
}
@end
@implementation VerlaufView
@synthesize mainLayer;
-(void) initialisieren
{
if( debug ) NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
VerlaufDelegate* layerDelegate = [[VerlaufDelegate alloc] initWithView:self];
float width = 200; //320;
float height = 100; //259;
//Hauptlayer
mainLayer = [[CALayer alloc] init];
mainLayer.delegate = layerDelegate;
mainLayer.bounds = CGRectMake( 0.f, 0.f, width, height );
/*mainLayer.backgroundColor = [[UIColor whiteColor] CGColor];
mainLayer.cornerRadius = 10.f;
CGFloat components[4] = { 0.0, 0.0, 0.0, 1.0 };
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGColorRef black = CGColorCreate( colorspace, components );
mainLayer.borderColor = black;
mainLayer.borderWidth = 1.f;
mainLayer.shadowRadius = 5.f;
mainLayer.shadowColor = black;
CGColorRelease( black );
CGColorSpaceRelease(colorspace);
mainLayer.shadowOffset = CGSizeMake( 0.f, 5.f ),
mainLayer.shadowOpacity = 0.75f;
*/
[self.layer insertSublayer:mainLayer above:self.layer];
[mainLayer setNeedsDisplay];
if( debug ) NSLog(@">>> Leaving %s <<<", __PRETTY_FUNCTION__);
}
@end
所以我的代码在处理“initialisieren”方法时崩溃了。
【问题讨论】:
标签: ios uitableview calayer