遍历 UIView 中的自定义对象并找到匹配的属性 [英] Iterate through custom objects in a UIView and find matching properties
问题描述
我有一个加载了几个自定义 NSObjects (graphShape) 的 UIView.每个 graphShape 对象都有一个名为 shapeName 的属性.我可以像这样访问这个属性:
I have a UIView that gets loaded with several custom NSObjects (graphShape). Each graphShape object has a property called shapeName. I can access this property like this:
graphShape * myNewShape = [doShapes objectAtIndex:i];
NSLog(@"myNewShape Name: %@", myNewShape.shapeName);
//Logs: myNewShape Name: redshape
NSArray (doShapes) 包含视图包含的一些 shapeNames 的列表(即:'redshape' 和 'yellowshape'),我需要更改匹配对象的另一个属性如何在我的视图中遍历 graphShape 对象的所有实例并找到具有redshape"和yellowshape"属性的实例?
The NSArray (doShapes) contains a list of some shapeNames that the View contains (ie: 'redshape', and 'yellowshape') and I need to change another property of the matched object How do I loop through all of the instances of the graphShape object in my view and find the ones that have the property 'redshape' and 'yellowshape'?
推荐答案
您是否正在寻找:
for (graphShape * shape in doShapes){
if ( [shape.shapeName isEqualToString:@"redshape"] ){
//do stuff
}
}
这篇关于遍历 UIView 中的自定义对象并找到匹配的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!