- 我以编程方式创建了
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/