2011-11-15 58 views
0

这个SHOULD是简单的。相反,在最后一个小时左右,我感到困惑。无论我做什么,这个变量拒绝改变值


头文件:

CellBackgroundView距离的UIView衍生的自定义类。

@interface CustomCell : UITableViewCell { 

    CellBackgroundView *customBackgroundView; 

} 

@property (strong) CellBackgroundView *customBackgroundView; 
预期不起作用


代码:

所有我想要做的就是分配东西customBackgroundView。

customBackgroundView = [[CellBackgroundView alloc] initWithFrame:CGRectZero]; 
    [self addSubview:customBackgroundView]; 

-

什么也没有发生。在调试器中,我可以看到customBackgroundView是0x0。以下也不起作用,虽然“背景”确实分配了一个内存位置。 customBackgroundView仍然是0x0。

CellBackgroundView *background = [[CellBackgroundView alloc] initWithFrame:CGRectZero]; 
    customBackgroundView = background. 
    [self addSubview:customBackgroundView]; 


发生了什么事?为什么这不起作用? 我打开了ARC。


EDITS:

CellBackgroundView的基础是:

- (BOOL) isOpaque { 
    return NO; 
} 

-(void)drawRect:(CGRect)aRect { 
    //Custom drawing code 
} 

而且,上面的代码,当我用的UITableViewCell的官方 'backgroundView' 属性的罚款。

+0

任何东西CellBackgroundView执行有关?像一个自定义的initWithFrame? – djromero

+0

你可以发布'CellBackgroundView'的'initWithFrame:'方法吗?它可能是通过它CGRectZero返回零。 – jbat100

+0

@madmw我已经发布了该类的基础 - 请参阅底部的编辑。 –

回答

1

最后....答案确实是Xcode坏了。

或者说,调试器是。无论我设置该变量,Xcode都拒绝在调试器中显示。但是,代码实际上按照它应该的方式工作。

修复它,请苹果。

+1

请使用最新版本的iOS试用xCode 4.2。我也遇到了你用xCode 4.0遇到的问题! – tipycalFlow

1

尝试的

@property (nonatomic,retain) CellBackgroundView *customBackgroundView; 

代替strong,看看是否有帮助...这似乎是一个内存分配问题

+0

虽然没有区别,好主意。我也试过'分配',也没有这样的运气。 –

+0

你也必须综合这个属性......否则你会得到一个警告 – tipycalFlow

+0

是的,它也是合成的。我甚至尝试写我自己的二传手和吸气者,认为这是搞砸了。不过,同样的行为! –

0

我改变了类型为一个UIView。我拿走了财产并合成了声明。我'清理'了这个项目。

所以我的代码现在只是:

@interface CustomCell : UITableViewCell { 

    UIView *customBackgroundView; 

} 

// m-file 

customBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 10, 10)]; 


结果:这是行不通的。 customBackgroundView仍然为零。我的结论是,无论我是疯了还是X代码都坏了。

+0

哈哈...清理项目,然后重新启动它,然后......没有了XCode有时 – tipycalFlow

+0

行动起来@tipycalFlow清洗和重新启动好几遍了... :) –

+0

的NSLog直接[UIView的页头] initWithFrame:方法CGRectMake(10,10 ,10,10)]看看它是否为零(不应该)。如果不是零,请尝试将customBackgroundView更改为NSString并使用customBackgroundView = @“My string”; – jptsetung

相关问题