gpt4 book ai didi

ios- "swapping"UIViews 可能吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:14:45 24 4
gpt4 key购买 nike

这是我的代码:

if([pantallas objectForKey:par]){
UIView *vista= [[UIView alloc] initWithFrame:self.Botones.frame];
vista.backgroundColor= [UIColor brownColor];

CGSize la= CGSizeMake(50,60);
int cuantos= [part2 count];
NSArray *arr= [COLGenerales tileN:cuantos RectsOfSize:la intoSpaceOf:vista.frame withMaxPerRow:5 spaceVertical:10 spaceHorizontal:10];
for(int j=0; j<cuantos; j++){
UIButton *bot= [[UIButton alloc] initWithFrame:[[arr objectAtIndex:j] CGRectValue]];
bot.tag=j;
bot.titleLabel.text=par;
bot.titleLabel.hidden=true;
bot.imageView.image = [UIImage imageNamed:[[part2 allKeys] objectAtIndex:j]];
[bot addTarget:self action:@selector(registrar:) forControlEvents:UIControlEventTouchDown];
[vista addSubview:bot];

}

[pantallas setObject:vista forKey:par];

self.Botones= vista;
}else{
self.Botones= [pantallas objectForKey:par];
}

Botones是一个简单的 View 嵌入到这个类控件的 View 中(首先由Nib文件发起),COLGenerales的类方法返回一个编码为NSValues的CGRects数组,registrar:是一个本地方法。

一切都已正确设置(我已经用调试器彻底检查过了)。 View 已成功创建、设置并添加到字典中。

但是,我绝对不会更改实际屏幕。我什至包括了背景颜色的变化,只是为了检查按钮是否有问题。没有什么。对此有什么建议的解决方案吗?

最佳答案

作为 IBOutlet 的属性与 View 层次结构没有内在联系——它只能从 xib 填充该属性。当您设置 self.Botones 时,您需要执行如下操作:

[self.Botones removeFromSuperview];
self.Botones = newValue;
[self.BotonesSuperview addSubview:self.Botones];

如果您在许多地方更新 self.Botones,并且您总是希望更改反射(reflect)在屏幕上,您可以将其添加到 setter 实现中:

-(void)setBotones:(UIView*)newValue {
if (newValue != _Botones) {
[_Botones removeFromSuperview];
_Botones = newValue;
[self.BotonesSuperview addSubview:_Botones];
}
}

关于ios- "swapping"UIViews 可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15796324/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com