gpt4 book ai didi

ios:通过循环命名 View

转载 作者:行者123 更新时间:2023-12-01 16:37:05 26 4
gpt4 key购买 nike

只是想知道如何动态地命名 Uiviews 或变量,然后在 Obj C(X 代码)中引用它们,并且一旦创建了引用它们的最佳方式。

我在其他地方读到您应该在数组中定义列表然后创建,但问题是我的用户数是动态的。

 for(int x = 0; x <= 10; x++)
{
UIView *"User_"&(x) = [[UIView Alloc] init];
User_x.frame = CGRectMake( 10 * x , 10 , 10 ,10);
}

做这样的事情的最佳方法是什么?

最佳答案

如果您的项目有 ARC=Yes ,编译器会删除你的 View 的foreach循环引用。
但是,您可以在 View 上添加标签:

for(int x = 0; x <= 10; x++) 
{
UIView *user = [[UIView Alloc] init];
user.tag=x;
User.frame = CGRectMake( 10 * x , 10 , 10 ,10);
[yourSuperView addSubview:user];
}

关于ios:通过循环命名 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27269067/

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