iOS中的UIScrollView错误

iOS中的UIScrollView错误,ios,objective-c,uiscrollview,Ios,Objective C,Uiscrollview,我不熟悉UIScrollView。我不知道如何添加按钮与他们。在我的应用程序中,我需要一个水平视图按钮。但当我试图以编程方式创建UIScrollView时,它不起作用。它抛出了一些错误。请帮帮我 我也尝试过使用故事板实现这一点,但失败了,因为我不知道如何使用viewDidLoad将两者连接起来 这是我迄今为止使用的代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after lo

我不熟悉UIScrollView。我不知道如何添加按钮与他们。在我的应用程序中,我需要一个水平视图按钮。但当我试图以编程方式创建UIScrollView时,它不起作用。它抛出了一些错误。请帮帮我

我也尝试过使用故事板实现这一点,但失败了,因为我不知道如何使用viewDidLoad将两者连接起来

这是我迄今为止使用的代码:

    - (void)viewDidLoad
{
      [super viewDidLoad];
// Do any additional setup after loading the view.
    self.layerPosition = self.toplayer.frame.origin.x;

    UIScrollView *scrollview =[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
     scrollview.showsHorizontalScrollIndicator=YES;
     scrollview.userInteractionEnabled=YES;
     scrollview.scrollEnabled=YES;

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button addTarget:self action:@selector(newView:)   forControlEvents:UIControlEventTouchDown];

    [button setTitle:@"Excavations",@"Concrete",@"Framing",@"Insulation" forState:UIControlStateNormal];
   button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);

   [self.view addSubview:scrollview];
   scrollview.contentSize = CGSizeMake(320,960);

}
如果我做错了,请告诉我正确的程序


谢谢

我现在只看到您代码中的一个错误:

[按钮设置标题:@开挖、@混凝土、@框架、@绝缘状态:UIControlStateNormal]

setTitle:仅需一个字符串,请尝试以下操作:

[button setTitle:@"Excavations" forState:UIControlStateNormal];
您可能想在滚动视图中添加此按钮,因此需要调用:

[scrollview addSubview:button];
如果不发布您的错误,它应该会有所帮助


我假设您希望将UIControlEventTouchUpInside而不是UIControlEventTouchDown作为按钮控件事件传递。

试试这个。它会起作用的

- (void)viewDidLoad
    {
          [super viewDidLoad];
    // Do any additional setup after loading the view.
        self.layerPosition = self.toplayer.frame.origin.x;

        UIScrollView *scrollview =[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
         scrollview.showsHorizontalScrollIndicator=YES;
         scrollview.userInteractionEnabled=YES;
         scrollview.scrollEnabled=YES;

        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button addTarget:self action:@selector(newView:)   forControlEvents:UIControlEventTouchDown];

        [button setTitle:@"Excavations" forState:UIControlStateNormal];
       button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);

       [self.view addSubview:scrollview];
       scrollview.contentSize = CGSizeMake(320,960);

    }

scrollview.backgroundColor=[UIColor greenColor];如果您想查看它的位置,请添加此项。