gpt4 book ai didi

iOS:如何将内容从 ScrollView 复制到另一个 ScrollView

转载 作者:行者123 更新时间:2023-11-29 10:42:39 31 4
gpt4 key购买 nike

  • 我以编程方式创建了 UIScrollView 并向其中添加了多个 button
  • 它运行良好,没有任何问题。
  • 但我需要通过复制先前 ScrollView 的内容来创建另一个 ScrollView

查询: 如何将First_Scrollview内容复制到Second_Scrollview

代码:

- (void)ScrollviewItems
{
int x = 5;
int y = 5;
for(int i=0; i<totalButtonsCount; i++)
{
CategoryItem = [[UIButton alloc]initWithFrame:CGRectMake(x, y, buttonWidth, 50)];
CategoryItem.titleLabel.backgroundColor = [UIColor clearColor];
CategoryItem.backgroundColor = [UIColor redColor];
[CategoryItem setTitle:[NSString stringWithFormat:@"%d",i]
forState:UIControlStateNormal];
CategoryItem.tag = i;
[CategoryItem addTarget:self
action:@selector(CategoryItemAction:)
forControlEvents:UIControlEventTouchUpInside];
[First_Scrollview addSubview:CategoryItem];
x = x + (buttonWidth + 5);
}
First_Scrollview.contentSize = CGSizeMake(x,50);

Second_Scrollview = [self.Category_Scrollview copy]; // Error
}

错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIScrollView copyWithZone:]: unrecognized selector sent to instance 

最佳答案

你也可以通过这个for循环来做到这一点

for(UIView *v in self.scrollview1.subviews){
[self.scrollview2 addSubview:v];
}

关于iOS:如何将内容从 ScrollView 复制到另一个 ScrollView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23752127/

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