ios - 检查类的特定实例是否已经存在

标签 ios objective-c class instance

有没有检查一个类的特定实例是否已经被创建。我觉得很难检查实例是否已经存在,因为您可能还没有创建实例。

这是我的代码:

-(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/

相关文章:

ios - 不支持的配置 : This file is set to build for a version older than the deployment target. 功能可能受限

objective-c - Xcode 符号图标...最终列表?

ios - 尝试移动 UITableView 行时崩溃

ios - Objective-C指针类型的隐式转换 'dispatch_source_t'

ios - Cocoa 单例和共享实例

java - 无法在 JAVA 中将变量从子级返回到父级(选项窗口)

iphone - 什么是 UIGobblerGestureRecognizer?

ios - Swift 中的 UIPickerView 子类 : error optional value in viewForRow

C++ 通用对象指针

java - 当我点击 Android 应用程序中的 "Notes"按钮时,如何调用我的 NoteMain 类