简体   繁体   中英

why the button is not calling the other method?

i am new to iOS here is my code

    -(void)getImageV{
    internet *myClass = [[internet alloc]init];
    if ([myClass connectedToInternet]) {
    NSUInteger x =[_relatedOffers count];
    self.scrollViewTest.contentSize = CGSizeMake(x*172, _scrollViewTest.frame.size.height);

    for (int pos=0; pos<[_relatedOffers count]; pos++) {       

        NSLog(@"-------->%d",pos);
        UIButton* aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        NSLog(@"------>%@",aButton);
        [aButton setTag:pos];
        [aButton setBackgroundColor:[UIColor redColor]];
        [aButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        CGRect buttonFrame = CGRectMake(pos*150, 0, 158, 70);
        buttonFrame.size = CGSizeMake(140, 90);
        aButton.frame = buttonFrame;       
        [self.relatedViewOffer addSubview:aButton];
        NSLog(@"-------->%@",aButton);
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSArray *myOrigan = [_relatedOffers objectAtIndex:pos];
            NSURL *aURL = [NSURL URLWithString:[[myOrigan valueForKeyPath:@"offer_image"]stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
            UIImage *aImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:aURL]];
            UIImage *image = [MYUtil imageWithImage:aImage scaledToSize:CGSizeMake(158, 70)];
            aImage = nil;
            if(image)
            {
                dispatch_async(dispatch_get_main_queue(), ^{
                [aButton setBackgroundImage:image forState:normal];

                });
            }
        });

    }
    }else{
        [self.view sendSubviewToBack:_rotateView];
        [_rotate stopAnimating];
    }
}

- (void)buttonClicked:(UIButton*)button {
    [self.view bringSubviewToFront:_rotateView];
    [_rotate startAnimating];
    [_relatedViewOffer setHidden:YES];
     _offers =nil;
     _offers = [_relatedOffers objectAtIndex:[button tag]];
    NSArray * allSubviews = [self.relatedViewOffer subviews];
    for(UIView *view in allSubviews)
    {
        if([view isMemberOfClass:[UIButton class]])
        {
            [view removeFromSuperview];
        }
    }    
     [self viewDidLoad];
     [self viewDidAppear:YES];
}

i am creating horizontal scroll view .In this scroll view buttons are added but upto 7 buttons it is working well after that it is not working ? please solve this problem.

Thanks in advance..

Add the following: self.relatedViewOffer.clipsToBounds = YES; and figure out if the buttons are still visible. If not, that the buttons are outside of the bounds of self.relatedViewOffer . Buttons that are outside of the bounds of its super view don't receive touch events.

If you can't see the button, you need to make self.relatedViewOffer big enough to fit all buttons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM