Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在objective-c中查找类的多个实例_Objective C_Ios4 - Fatal编程技术网

如何在objective-c中查找类的多个实例

如何在objective-c中查找类的多个实例,objective-c,ios4,Objective C,Ios4,我有一个UIView类,它有UITextField子类的许多子视图。有没有一种方法可以遍历类列表来查找UITextField子类是的 假设将代码放在UIView子类中,则可以获取子视图数组 NSArray *sbviews = [self subviews]; NSMutableArray *textFields; //placeholder for your UITextField subclassed objects. //enumerate through the subview col

我有一个UIView类,它有UITextField子类的许多子视图。有没有一种方法可以遍历类列表来查找UITextField子类

是的

假设将代码放在UIView子类中,则可以获取子视图数组

NSArray *sbviews = [self subviews];
NSMutableArray *textFields; //placeholder for your UITextField subclassed objects.

//enumerate through the subview collection and only add objects to the textFields array that are UITextField objects.
for (id anObject in sbviews) {
    if([anObject isKindOfClass: [UITextField class]]){
        [textField addObject: anObject];
    }
}

textField数组现在将包含属于UITextField类的所有对象…

您的UIView类有一个子视图数组,其中列出了您添加到其中的所有子视图。您可以遍历数组并查找UITextField对象的实例(而不是类)

for (UITextField* textField in [someView subviews]) {
    if ([textField isKindOfClass:[UITextField class]]) {
        // found one, textField really is a UITextField
    }
}

正是我想要的-非常感谢