0
votes

i have UIScrollView it has next button when click it run this code

-(IBAction)ScrollPage:(id)sender {

        NSLog(@"ScrollPage Called");
        NSInteger positionX;
        if ([sender tag] == 1) {
            positionX = AddNewScroll.contentOffset.x - 320;
        }else {
            positionX = AddNewScroll.contentOffset.x + 320;
        }
        [AddNewScroll setContentOffset:CGPointMake(positionX,0) animated:YES];

    }

and it will move the scroll to new page , then i have button there when click it will call

-(IBAction)SelectImg:(id)sender {

    UIActionSheet *imgMenu = [[UIActionSheet alloc] initWithTitle:@"choose image"
                                                         delegate:self
                                                cancelButtonTitle:@"Cancel"
                                           destructiveButtonTitle:@"Camera"
                                                otherButtonTitles:@"Album",nil];
    imgMenu.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    [imgMenu showInView:[UIApplication sharedApplication].keyWindow];

}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    imgPicker = [[UIImagePickerController alloc] init];
    imgPicker.allowsEditing = YES;
    imgPicker.delegate = self;


    @try {
        if (buttonIndex == 0) {
            imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentModalViewController:imgPicker animated:YES];
        }

        if (buttonIndex == 1) {
            imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

            //Start iPhone PhotoLibrary
            if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
                [self presentModalViewController:imgPicker animated:YES];

            } else
            //Start iPad  PhotoLibrary
            if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPad){
                aPopover = [[UIPopoverController alloc] initWithContentViewController:imgPicker];
                [aPopover presentPopoverFromRect:CGRectMake(250, 40, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

            }
        }
    }

the Problem is when it call the actionSheet the UIScrollView by itself go to first page contentOffset to 0 then call scrollViewDidScroll

ps. Paging Disable

1

1 Answers

0
votes

In the method clickedButtonAtIndex, you are re-allocating your UIImagePickerController. Isn't that the reason why it goes back to 0?

Also, what relation is there between AddNewScroll and imgPicker?