0

My UIScrollView is not responding to touch events, nor is my touchesBegain method being called for my UIViewController. (Also the text on my buttons are distorted on one and not shown on the other)

In Storyboard I added the ScrollView to the UIViewController and added my UITextFields and UIButtons to the ScrollView

Here is the code:

#import <UIKit/UIKit.h>

@interface RefineSearchViewController : UIViewController <UITextFieldDelegate, UIScrollViewDelegate>
{
    IBOutlet UIScrollView *scroller;
}

@property (strong, nonatomic) IBOutlet UITextField *nameField;
@property (strong, nonatomic) IBOutlet UITextField *targetField;
@property (strong, nonatomic) IBOutlet UITextField *vendorField;
@property (strong, nonatomic) IBOutlet UITextField *CATField;
@property (strong, nonatomic) IBOutlet UITextField *clonalityField;
@property (strong, nonatomic) IBOutlet UITextField *sourceOrganismField;
-(IBAction) textFieldReturn: (id) sender;

#import "RefineSearchViewController.h"
#import "DBHandler.h"

@interface RefineSearchViewController ()

@end

@implementation RefineSearchViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [scroller setScrollEnabled:YES];

    // set the content size to be the size our our whole frame
     //scroller.frame = CGRectMake(74, 261, 620, 354);
    [scroller setContentSize:CGSizeMake(2000, 2000)];
    [scroller setCanCancelContentTouches:NO];
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.targetField.delegate = self;
    self.nameField.delegate = self;
    self.vendorField.delegate = self;
    self.clonalityField.delegate = self;
    self.sourceOrganismField.delegate = self;
    self.CATField.delegate = self;
}

-(void) viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = YES;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // If you are going to conduct a refine search
    if ([[segue identifier] isEqualToString:@"Refine"])
    {
        DBHandler *handler = [[DBHandler alloc]init];

        //Run searches on each of the parameter that aren't empty

        NSString *nameParameter = _nameField.text;
        if (![nameParameter isEqualToString:@""])
        {
        [handler search:0 andInput:nameParameter];
        }

        NSString *targetParameter = _targetField.text;
        if(![targetParameter isEqualToString:@""])
        {
            [handler search:1 andInput:targetParameter];
        }

        NSString *vendorParameter = _vendorField.text;
        if (![vendorParameter isEqualToString:@""])
        {
            [handler search:2 andInput:vendorParameter];
        }

        NSString *catParameter = _CATField.text;
        if (![catParameter isEqualToString:@""])
        {
            [handler search:3 andInput:catParameter];
        }

        NSString *clonalityField = _clonalityField.text;
        if (![catParameter isEqualToString:@""])
        {
            [handler search:4 andInput:clonalityField];
        }

        NSString *sourceField = _sourceOrganismField.text;
        if (![sourceField isEqualToString:@""])
        {
            [handler search:5 andInput:sourceField];
        }

        //recursive implementation
        for (int i = 0; i < 6 ; i++)
        {

        }

        //We shouldn't clear the text fields here in my personal opinion because they apply to the search until you return to the homescreen and reset what is the
        //current "working database"
    }

    //if you are going to cancel the refine search, simply go back to the previous screen
    else if ([[segue identifier] isEqualToString:@"Cancel"])
    {
        //Do Nothing
        //but more importantly....
        //....clear Text Fields
        _nameField.text = @"";
        _targetField.text = @"";
        _vendorField.text = @"";
        _CATField.text = @"";
        _clonalityField.text = @"";
        _sourceOrganismField.text = @"";
    }
}

//make that stubborn keyboard go away whenever you touch the background
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [_nameField resignFirstResponder];
    [_targetField resignFirstResponder];
    [_vendorField resignFirstResponder];
    [_CATField resignFirstResponder];
    [_clonalityField resignFirstResponder];
    [_sourceOrganismField resignFirstResponder];
}

-(IBAction)textFieldReturn:(id)sender
{
    [sender resignFirstResponder];
}

//following code was taken and tweaked from stack overflow
//- (void)textFieldDidBeginEditing:(UITextField *)textField
//{
//    [self animateTextField: textField up: YES];
//    NSLog(@"YO");
//}
//
//
//- (void)textFieldDidEndEditing:(UITextField *)textField
//{
//    [self animateTextField: textField up: NO];
//}
//
//- (void) animateTextField: (UITextField*) textField up: (BOOL) up
//{
//    const int movementDistance = 216; //height of the keyboard
//    const float movementDuration = 0.3f; // duration of the animation
//    
//    int movement = (up ? -movementDistance : movementDistance);
//    
//    [UIView beginAnimations: @"anim" context: nil];
//    [UIView setAnimationBeginsFromCurrentState: YES];
//    [UIView setAnimationDuration: movementDuration];
//    self.view.frame = CGRectOffset(self.view.frame, 0, movement);
//    [UIView commitAnimations];
//}

@end
dkirlin
  • 315
  • 4
  • 19
  • I hope you find below mentioned URLs helpful http://stackoverflow.com/questions/1685956/uiscrollview-touchesbegan http://stackoverflow.com/questions/2472145/how-does-uiscrollview-steal-touches-from-its-subviews – Deepesh Gairola May 14 '13 at 04:16

1 Answers1

1

Make sure your scrollView's delegate is set properly in storyboard and scrollView's userInteractionEnabled is set.

RTasche
  • 2,614
  • 1
  • 15
  • 19