ios 中 局部变量可以通过传递来进行管理和释放,通过多使用局部变量,可以提高代码的內聚度。如下:

-(void)someMethod
{
UILabel *label = [[UILabel alloc]init]; //局部变量
//设置 label 的属性等... [self.view addSubview:label]; [self performSelectorOnMainThread:@selector(labelWillDisappeared:) withObject:label waitUntilDone:NO];
} -(void)labelWillDisappeared:(UILabel *)label
{
[label removeFromSuperview]; [label release]; //在其它方法中释放局部变量
}
05-11 22:12