Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UIScrollView不滚动iOS_Ios_Uiscrollview - Fatal编程技术网

UIScrollView不滚动iOS

UIScrollView不滚动iOS,ios,uiscrollview,Ios,Uiscrollview,我试图在一个视图中创建几个UIScrollView,这些视图在iOS中水平滚动。这是我目前的代码: -(void)updateSection { [feedLoadingActInd stopAnimating]; feedLoadingActInd.hidden = YES; builder = [NSMutableArray array]; float xPosition = 0; float xPosBut = 0; scrollView

我试图在一个视图中创建几个UIScrollView,这些视图在iOS中水平滚动。这是我目前的代码:

-(void)updateSection {
    [feedLoadingActInd stopAnimating];
    feedLoadingActInd.hidden = YES;
    builder = [NSMutableArray array];
    float xPosition = 0;
    float xPosBut = 0;

    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 400, self.frame.size.width, self.frame.size.height - 29)];
    [scrollView setScrollEnabled:YES];
    scrollView.backgroundColor = [UIColor yellowColor];

    scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    scrollView.pagingEnabled = YES;
    scrollView.delegate = self;

    for (int i = 0; i < itemArticleArray.count; i++) {
        testButton = [[UIButton alloc] initWithFrame:CGRectMake(xPosBut, 40, 40, 40)];
        [testButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [testButton setTitle:@"Test" forState:UIControlStateNormal];
        [testButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
        testButton.backgroundColor = [UIColor blueColor];
        xPosBut += testButton.frame.size.width;
        NSLog(@"scroll.frame.size.width = %f", scrollView.frame.size.width);

        xPosition += 2;
        UIView *seperatorView = [[UIView alloc] initWithFrame:CGRectMake(xPosition, 4, 350, scrollView.frame.size.height - 8)];
        seperatorView.backgroundColor = [UIColor redColor];
        [scrollView addSubview:seperatorView];
        xPosition += 350;

        [seperatorView addSubview:testButton];
        [scrollView addSubview:seperatorView];
        [builder addObject:testButton];

    }
    [self addSubview:scrollView];
    [scrollView setUserInteractionEnabled:YES];
    [scrollView setContentSize: CGSizeMake(xPosition, scrollView.frame.size.height)];

    NSLog(@"scroll.contentsize.width = %f", scrollView.contentSize.width);
-(void)updateSection{
[FeedLoadingActin and Stop Animating];
feedLoadingActInd.hidden=是;
生成器=[NSMutableArray];
浮点xPosition=0;
float xPosBut=0;
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0400,self.frame.size.width,self.frame.size.height-29)];
[滚动视图设置可滚动:是];
scrollView.backgroundColor=[UIColor yellowColor];
scrollView.autoresizingMask=UIViewAutoresizingFlexibleWidth | UIViewAutoResizingFlexibleHight;
scrollView.PaginEnabled=是;
scrollView.delegate=self;
对于(int i=0;i[scrollView setContentSize:CGSizeMake(xPosition,scrollView.frame.size.height)];
NSLog(@“scroll.contentsize.width=%f”,scrollView.contentsize.width);
}

然而,没有一个滚动视图实际上是滚动的,我对此感到困惑,因为添加了多个按钮。另外,我添加的按钮在我按下时实际上没有任何作用。他们应该运行buttonPressed方法,但它没有

任何帮助都将不胜感激

试试这个

float xPosition = 0;
    float xPosBut = 0;

    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 100,self.view.frame.size.width, self.view.frame.size.height - 29)];
    [scrollView setScrollEnabled:YES];

    scrollView.backgroundColor = [UIColor yellowColor];

    for (int i = 0; i < 10; i++) {
       UIButton *testButton = [[UIButton alloc] initWithFrame:CGRectMake(xPosition, 10, scrollView.frame.size.width, 50)];
        [testButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [testButton setTitle:@"Test" forState:UIControlStateNormal];
        [testButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
        testButton.backgroundColor = [UIColor blueColor];
        xPosition += testButton.frame.size.width;
        NSLog(@"xposbut = %f", xPosBut);
        NSLog(@"scroll.frame.size.width = %f", scrollView.frame.size.width);

        xPosition += scrollView.frame.size.width+2;
        UIView *seperatorView = [[UIView alloc] initWithFrame:CGRectMake(xPosition, 4, 2, scrollView.frame.size.height - 8)];
        seperatorView.backgroundColor = [UIColor redColor];
        [scrollView addSubview:seperatorView];
        xPosition +=scrollView.frame.size.width+ 4;

        [self.view addSubview:scrollView];
        [scrollView addSubview:seperatorView];
        [scrollView addSubview:testButton];
        [builder addObject:testButton];

    }
    [scrollView setContentSize: CGSizeMake(xPosition, scrollView.frame.size.height)];
    [self.view addSubview:scrollView];
float xPosition=0;
float xPosBut=0;
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,100,self.view.frame.size.width,self.view.frame.size.height-29)];
[滚动视图设置可滚动:是];
scrollView.backgroundColor=[UIColor yellowColor];
对于(int i=0;i<10;i++){
UIButton*testButton=[[UIButton alloc]initWithFrame:CGRectMake(xPosition,10,scrollView.frame.size.width,50)];
[testButton setTitleColor:[UIColor greenColor]用于状态:UIControlStateNormal];
[testButton setTitle:@“测试”状态:UIControlStateNormal];
[testButton addTarget:self action:@selector(按钮按下)for ControlEvents:UIControlEventTouchUpInside];
testButton.backgroundColor=[UIColor blueColor];
xPosition+=testButton.frame.size.width;
NSLog(@“xposbut=%f”,xposbut);
NSLog(@“scroll.frame.size.width=%f”,scrollView.frame.size.width);
xPosition+=scrollView.frame.size.width+2;
UIView*separatorview=[[UIView alloc]initWithFrame:CGRectMake(xPosition,4,2,scrollView.frame.size.height-8)];
separatorview.backgroundColor=[UIColor redColor];
[滚动视图添加子视图:分隔视图];
xPosition+=scrollView.frame.size.width+4;
[self.view addSubview:scrollView];
[滚动视图添加子视图:分隔视图];
[滚动视图添加子视图:测试按钮];
[builder addObject:testButton];
}

[scrollView setContentSize:CGSizeMake(xPosition,scrollView.frame.size.height)]; [self.view addSubview:scrollView];
根据您的要求设置for循环条件部件。 希望这对你有帮助。

试试这个

float xPosition = 0;
    float xPosBut = 0;

    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 100,self.view.frame.size.width, self.view.frame.size.height - 29)];
    [scrollView setScrollEnabled:YES];

    scrollView.backgroundColor = [UIColor yellowColor];

    for (int i = 0; i < 10; i++) {
       UIButton *testButton = [[UIButton alloc] initWithFrame:CGRectMake(xPosition, 10, scrollView.frame.size.width, 50)];
        [testButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [testButton setTitle:@"Test" forState:UIControlStateNormal];
        [testButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
        testButton.backgroundColor = [UIColor blueColor];
        xPosition += testButton.frame.size.width;
        NSLog(@"xposbut = %f", xPosBut);
        NSLog(@"scroll.frame.size.width = %f", scrollView.frame.size.width);

        xPosition += scrollView.frame.size.width+2;
        UIView *seperatorView = [[UIView alloc] initWithFrame:CGRectMake(xPosition, 4, 2, scrollView.frame.size.height - 8)];
        seperatorView.backgroundColor = [UIColor redColor];
        [scrollView addSubview:seperatorView];
        xPosition +=scrollView.frame.size.width+ 4;

        [self.view addSubview:scrollView];
        [scrollView addSubview:seperatorView];
        [scrollView addSubview:testButton];
        [builder addObject:testButton];

    }
    [scrollView setContentSize: CGSizeMake(xPosition, scrollView.frame.size.height)];
    [self.view addSubview:scrollView];
float xPosition=0;
float xPosBut=0;
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,100,self.view.frame.size.width,self.view.frame.size.height-29)];
[滚动视图设置可滚动:是];
scrollView.backgroundColor=[UIColor yellowColor];
对于(int i=0;i<10;i++){
UIButton*testButton=[[UIButton alloc]initWithFrame:CGRectMake(xPosition,10,scrollView.frame.size.width,50)];
[testButton setTitleColor:[UIColor greenColor]用于状态:UIControlStateNormal];
[testButton setTitle:@“测试”状态:UIControlStateNormal];
[testButton addTarget:self action:@selector(按钮按下)for ControlEvents:UIControlEventTouchUpInside];
testButton.backgroundColor=[UIColor blueColor];
xPosition+=testButton.frame.size.width;
NSLog(@“xposbut=%f”,xposbut);
NSLog(@“scroll.frame.size.width=%f”,scrollView.frame.size.width);
xPosition+=scrollView.frame.size.width+2;
UIView*separatorview=[[UIView alloc]initWithFrame:CGRectMake(xPosition,4,2,scrollView.frame.size.height-8)];
separatorview.backgroundColor=[UIColor redColor];
[滚动视图添加子视图:分隔视图];
xPosition+=scrollView.frame.size.width+4;
[self.view addSubview:scrollView];
[滚动视图添加子视图:分隔视图];
[滚动视图添加子视图:测试按钮];
[builder addObject:testButton];
}

[scrollView setContentSize:CGSizeMake(xPosition,scrollView.frame.size.height)]; [self.view addSubview:scrollView];
根据您的要求设置for循环条件部件。 希望这对你有帮助。

试试这个

float xPosition = 0;
    float xPosBut = 0;

    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 100,self.view.frame.size.width, self.view.frame.size.height - 29)];
    [scrollView setScrollEnabled:YES];

    scrollView.backgroundColor = [UIColor yellowColor];

    for (int i = 0; i < 10; i++) {
       UIButton *testButton = [[UIButton alloc] initWithFrame:CGRectMake(xPosition, 10, scrollView.frame.size.width, 50)];
        [testButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [testButton setTitle:@"Test" forState:UIControlStateNormal];
        [testButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
        testButton.backgroundColor = [UIColor blueColor];
        xPosition += testButton.frame.size.width;
        NSLog(@"xposbut = %f", xPosBut);
        NSLog(@"scroll.frame.size.width = %f", scrollView.frame.size.width);

        xPosition += scrollView.frame.size.width+2;
        UIView *seperatorView = [[UIView alloc] initWithFrame:CGRectMake(xPosition, 4, 2, scrollView.frame.size.height - 8)];
        seperatorView.backgroundColor = [UIColor redColor];
        [scrollView addSubview:seperatorView];
        xPosition +=scrollView.frame.size.width+ 4;

        [self.view addSubview:scrollView];
        [scrollView addSubview:seperatorView];
        [scrollView addSubview:testButton];
        [builder addObject:testButton];

    }
    [scrollView setContentSize: CGSizeMake(xPosition, scrollView.frame.size.height)];
    [self.view addSubview:scrollView];
float xPosition=0;
float xPosBut=0;
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,100,self.view.frame.size.width,self.view.frame.size.height-29)];
[滚动视图设置可滚动:是];
scrollView.backgroundColor=