我有这个代码:
-(IBAction) doSomething{
FirstViewController *firstViewController = [[[FirstViewController alloc]init]autorelease];
[firstViewController.label1 setAlpha:1.00];
[firstViewController.label2 setAlpha:1.00];
}
-(void) do{
//use firtsViewController in this method
}
正如您在示例中看到的那样,我使用了 FirstViewController 类的对象“firstViewController”,但是如果我想在方法“do”中使用相同的对象呢?我该怎么办
最佳答案
在标题中有...
FirstViewController *firstViewController;
然后将您的方法替换为...
-(IBAction) doSomething{
if(firstViewController == nil) {
firstViewController = [[FirstViewController alloc]init];
}
[firstViewController.label1 setAlpha:1.00];
[firstViewController.label2 setAlpha:1.00];
}
并添加..
- (void)dealloc {
[firstViewController release];
[super dealloc];
}
关于objective-c - IOS:处理一个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6387216/