‘self’时使用的实例变量未设置为'[(super或self)init …]的结果
一个
- (ID)initWithCoder:(NSCoder *)decoder { if (![super init]) return nil; red = [decoder decodefloatForKey:kRedKey]; //occurs here green = [decoder decodefloatForKey:kGreenKey]; blue = [decoder decodefloatForKey:kBlueKey]; return self;}
乙
- (ID)initWithFrame:(CGRect)frame Title:(Nsstring*)str sIDeUp:(BOol)up{ if(![super initWithFrame:frame]) return nil; int y; UIImage *img; if(up){ img = [UIImage imagenamedTK:@"Tapkulibrary.bundle/Images/graph/popup"]; y = 5; }else{ img = [UIImage imagenamedTK:@"Tapkulibrary.bundle/Images/graph/popdown"]; y = 14; } background = [[UIImageVIEw alloc] initWithImage:img]; // occurs here
C
- (ID) initWithFrame:(CGRect)frame { if(![super initWithFrame:frame]) return nil; UILabel *TitleBackground = [[[UILabel alloc] initWithFrame: CGRectMake(0,480,40)] autorelease]; TitleBackground.backgroundcolor = [UIcolor whitecolor]; [self addSubvIEw:TitleBackground]; TitleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; // occurs here
对于块A,这是正确的
self = [self init]; if( self != nil ){
和B& C
- (ID) initWithFrame:(CGRect)frame { super = [super initWithFrame:frame] if(super != nil) {@R_403_6120@ 一般来说,你应该写:
self = [super init...]; // Potentially change "self"if (self) { something = x; another = y;}return self;
这是因为在某些情况下init可能不会返回原始的self值.
总结以上是内存溢出为你收集整理的objective-c – Obj-C,’self’未设置为'[(super或self)init …]的结果时使用的实例变量全部内容,希望文章能够帮你解决objective-c – Obj-C,’self’未设置为'[(super或self)init …]的结果时使用的实例变量所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)