我有一个UIView
加载到 aViewController
并希望在加载后带来更改(例如,当您单击它UIView
以更改文本颜色时)
@interface CategoryMenu : UIView
{
UIImageView *img;
UIButton *disclosureBtn;
UIButton *actionView;
UILabel *titleLabel;
}
@property (nonatomic,retain) IBOutlet UIImageView *img;
@property (nonatomic,retain) IBOutlet UIButton *disclosureBtn;
@property (nonatomic,retain) IBOutlet UIButton *actionView;
@property (nonatomic,retain) IBOutlet UILabel *titleLabel;
通过这种方式,我已将其加载UIView
到UIViewController's
需要的地方。
-(void)showSubviews
{
int x = 0;
for (int i = 0; i < array.count ; i++)
{
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"CustomMenu" owner:self options:nil];
CategoryMenu* tempUserView = [nibViews objectAtIndex:0];
tempUserView.userInteractionEnabled = YES;
[tempUserView setFrame:CGRectMake(0, x, 280, 50)];
x+=60;
tempUserView.tag = i;
tempUserView.titleLabel.text = [array objectAtIndex:i];
[tempUserView.actionView addTarget:self action:@selector(ExtendedCollapsed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:tempUserView];
}
现在,当您按下 a 时UIView
,除了动作本身之外,我还想更改UILabel
文本的颜色。
-(void)ExtendedCollapsed:(id)sender
{
NSLog(@"[self.view subviews] = %@",[self.view subviews]);
UIView *view1 = (UIView *)sender;
for(UIView *view in [self.view subviews])
{
NSLog(@"view = %@ \n ", view);
if([view isKindOfClass:[CategoryMenu class]])
{
if (view.tag == view1.tag)
{
NSLog(@"We find the view !!!!");
CategoryMenu* tempUserView = (CategoryMenu*)view1;
NSLog(@"tempUserView = %@ \n ", tempUserView);
tempUserView.titleLabel.text = @"Text Changed";
tempUserView.titleLabel.textColor = [UIColor whiteColor];
NSLog(@"tempUserView.titleLabel.text = %@",tempUserView.titleLabel.text);
break;
}
}
else
{
NSLog(@"view is not a button");
}
}
}
看不到UIViews
之前加载的任何变化。
有人可以帮我一些建议吗?谢谢