access UIView objects in array
i´ve defined an a开发者_如何学Gorray which contents 4 UIView objects which were already defined
NSArray *districtArray = [NSArray arrayWithObjects:view1, view2, view3, view4, nil];
now i´d like to add a subview to an UIView accessing the array via an index. i can´t figure out how i have to write that
it should be something like that
[districtArray[0] addSubview:poiObject];
could anybody give me a hint about the syntax?
thank you!
To get the n-th object in an NSArray, use
[array objectAtIndex:n]
e.g.
[[districtArray objectAtIndex:0] addSubview:poiObject];
Edit: Starting from Xcode 4.4 (2012 Jul) OP's syntax is supported, i.e.
[districtArray[0] addSubview:poiObject];
does work as expected. This is known as object subscripting.
精彩评论