Ios 已加载对UIView元素的更改

Ios 已加载对UIView元素的更改,ios,uiview,Ios,Uiview,我将UIView加载到ViewController中,并希望在加载后进行更改(例如,当您单击该UIView以更改文本颜色时) 通过这种方式,我已将此UIView加载到所需的UIViewController的中 -(void)showSubviews { int x = 0; for (int i = 0; i < array.count ; i++) { NSArray* nibViews = [[NSBundle mainBundle] loa

我将
UIView
加载到
ViewController
中,并希望在加载后进行更改(例如,当您单击该
UIView
以更改文本颜色时)

通过这种方式,我已将此
UIView
加载到所需的
UIViewController的

  -(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];
    }
未看到先前加载的
ui视图的任何更改

有人能帮我提些建议吗?
谢谢

-(void)ExtendedCollapsed:(id)sender
中的sender参数是您的
ui按钮*actionView
而不是
类别菜单

我假设您在
CategoryMenu
类实现中有一个方法,它将
actionView.tag
设置为
CategoryMenu
对象
tag
,这样您就可以在
-(void)ExtendedCollapsed:(id)sender>中的循环中比较它们,并找到相应的
CategoryMenu

如果是这样,你甚至不必这样做,只要调用
sender.superview
,你就会得到与按下的
actionView
对应的
CategoryMenu
对象。如果
[sender.superview是类:[CategoryMenu class]]==TRUE
,您就可以开始了

然后,在更改了
tempUserView.titleLabel的颜色后,尝试调用
[tempUserView setNeedsLayout]

该方法现在应该如下所示:

- (void)ExtendedCollapsed:(id)sender {
    if ([sender isKindOfClass:[UIButton class]]) {
        if ([sender.superview isKindOfClass:[CategoryMenu class]]) {
            CategoryMenu *tempUserView = (CategoryMenu *)sender.superview;
            tempUserView.titleLabel.text = @"Text Changed";
            tempUserView.titleLabel.textColor = [UIColor whiteColor];
            [tempUserView setNeedsLayout];
        }
    }
}

在showsubviews中,您在数组中填充什么?nslog for tempUserView正在显示值?是的,此nslog正在显示信息。我写这行是因为我想检查UIView的地址。Jonathan-我使用此数组保留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");
        }
    }

}
- (void)ExtendedCollapsed:(id)sender {
    if ([sender isKindOfClass:[UIButton class]]) {
        if ([sender.superview isKindOfClass:[CategoryMenu class]]) {
            CategoryMenu *tempUserView = (CategoryMenu *)sender.superview;
            tempUserView.titleLabel.text = @"Text Changed";
            tempUserView.titleLabel.textColor = [UIColor whiteColor];
            [tempUserView setNeedsLayout];
        }
    }
}