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

标签 ios objective-c uiscrollview uibutton

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

相关文章:

ios - 如何将 UIScrollView 内容大小配置为具有固定宽度和动态高度?

ios - 设置作为 subview 的 UIScrollView 的 contentSize

ios - 编译适用于 iOS 6 和 iOS 7 的应用程序

ios - UIVisualEffectView 活力未在设备上显示(但在模拟器中显示)

ios - 如何从 UITextField 中获取非英文字符并将其视为普通字符

swift - 在 Swift 4.0 中阻止 UIScrollView 垂直滚动的问题

ios - 在 MKMapView 上检测动画的结束

ios - UIAlertController 仅在 2 秒后关闭

iphone - 文件中缺少所需的架构 armv7?

objective-c - objective-c UIAlertView队列