How do i refer to a UIButton inside an NSMutableArray?
This is the code i've tri开发者_StackOverflowed modifying, to no avail every time:
(UIButton *)[colourButtonsArray objectAtIndex:2].text = @"Test";
I get an error of 'Request for member 'text' in something not a structure or union.
Any ideas how to solve this?
Call the correct method:
[(UIButton *)[colourButtonsArray objectAtIndex:2] setTitle:@"Test" forState:UIControlStateNormal];
Documentation Here: http://developer.apple.com/library/ios/documentation/uikit/reference/UIButton_Class/UIButton/UIButton.html#//apple_ref/occ/instm/UIButton/setTitle:forState:
If you just want to cast and access properties you can just add more parenthesis (although text is not an actual property):
((UIButton *)[colourButtonsArray objectAtIndex:2]).buttonType;
To avoid extra parentheses with casting, you can use method syntax instead of dot notation. However, in the case of a UIButton... you set a UIButton's text with setTitle:forState:
method.
精彩评论