有没有检查一个类的特定实例是否已经被创建。我觉得很难检查实例是否已经存在,因为您可能还没有创建实例。
这是我的代码:
-(IBAction)done:(id)sender
{ //I want to figure out how to check if 'newWindow' already exists before I create another 'newWindow'
SimpleTableView *newWindow = [self.storyboard instantiateViewControllerWithIdentifier:@"SimpleTableView"];
[self.navigationController pushViewController:newWindow animated:YES];
}
感谢大家的帮助。
最佳答案
是的,有一种简单的方法。
您只需要对它有一些引用(例如创建一个属性)并检查它是否为 nil
(未初始化)。你可以这样做:
if(!myReference){
//if you get here it means that it hasn't been initialized yet so you have to do it
}
关于ios - 检查类的特定实例是否已经存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20939807/